一行に整数 a と b が空白一つで区切って与えられる。 次の四つの問いに順に一行ずつ答えよ。 ① a は b より小さいか? ② a と b は等しいか? ③ a は奇数か? (負の数も 2 で割り切れなければ奇数である。 -3 は奇数で、0 は偶数である。)
④ ① と ③ がどちらも真か? 真なら小文字で true、偽なら小文字で false を出力する。
a, b = map(int, input().split())less = a < bsame = a == bodd = a % 2 != 0 # 음수 홀수도 0이 아니다both = less and odd# print(True)는 True를 찍는다. 소문자로 바꿔 쓴다for v in (less, same, odd, both): print("true" if v else "false")
JavaScriptmain.js · 7 行
const [a, b] = require("fs").readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const less = a < b;const same = a === b;const odd = a % 2 !== 0; // -3 % 2는 -1이라 === 1로 물으면 안 된다const both = less && odd;// 불값은 문자열로 바뀌면 "true" / "false"다console.log([less, same, odd, both].join("\n"));
TypeScriptmain.ts · 7 行
import { readFileSync } from "node:fs";const [a, b]: number[] = readFileSync(0, "utf8").trim().split(/\s+/).map(Number);const less: boolean = a < b;const same: boolean = a === b;const odd: boolean = a % 2 !== 0;const both: boolean = less && odd;console.log([less, same, odd, both].join("\n"));
JavaMain.java · 18 行
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); boolean less = a < b; boolean same = a == b; boolean odd = a % 2 != 0; // -3 % 2 == -1 boolean both = less && odd; // Java는 boolean을 true / false로 찍는다 System.out.println(less); System.out.println(same); System.out.println(odd); System.out.println(both); }}
C#Main.cs · 22 行
using System;class Program{ static string Word(bool v) => v ? "true" : "false"; static void Main() { string[] p = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); int a = int.Parse(p[0]); int b = int.Parse(p[1]); bool less = a < b; bool same = a == b; bool odd = a % 2 != 0; bool both = less && odd; // Console.WriteLine(true)는 True(대문자)를 찍는다 Console.WriteLine(Word(less)); Console.WriteLine(Word(same)); Console.WriteLine(Word(odd)); Console.WriteLine(Word(both)); }}
C++main.cpp · 12 行
#include <iostream>int main() { int a, b; std::cin >> a >> b; bool less = a < b; bool same = a == b; bool odd = a % 2 != 0; bool both = less && odd; // std::boolalpha가 없으면 1과 0으로 찍힌다 std::cout << std::boolalpha << less << "\n" << same << "\n" << odd << "\n" << both << "\n";}
Cmain.c · 16 行
#include <stdbool.h>#include <stdio.h>static const char *word(bool v) { return v ? "true" : "false"; }int main(void) { int a, b; scanf("%d %d", &a, &b); bool less = a < b; bool same = a == b; bool odd = a % 2 != 0; /* -3 % 2 == -1 */ bool both = less && odd; /* C의 bool은 printf로 찍으면 1과 0이다 */ printf("%s\n%s\n%s\n%s\n", word(less), word(same), word(odd), word(both)); return 0;}
Craykonmain.cray · 12 行
p = コンソール.行読み().空白除去().分ける(" ");a = p[0].数に();b = p[1].数に();less = a < b;same = a == b;odd = a % 2 != 0; // -3 % 2는 -1이다both = less && odd;// 크레이콘은 참거짓을 true / false로 쓴다コンソール.書く(less);コンソール.書く(same);コンソール.書く(odd);コンソール.書く(both);