Official
A - What month is it? Editorial
by
A - What month is it? Editorial
by
sounansya
AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
入力例 \(2\) の \(X=1,Y=1\) の場合のように \(X\) と \(Y\) の両方が小さい場合の答えは \(X+Y\) となります。しかし、入力例 \(1\) のように \(X+Y\) が \(12\) より大きい場合は \(X+Y\) から \(12\) を引いた \(X+Y-12\) が答えとなります。
以上を適切に実装することでこの問題に正答することができます。
x, y = map(int, input().split())
if x + y <= 12:
print(x + y)
else:
print(x + y - 12)
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
if (x + y <= 12) {
cout << x + y << endl;
} else {
cout << x + y - 12 << endl;
}
return 0;
}
#include <stdio.h>
int main() {
int x, y;
scanf("%d %d", &x, &y);
if (x + y <= 12) {
printf("%d\n", x + y);
} else {
printf("%d\n", x + y - 12);
}
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
if (x + y <= 12) {
System.out.println(x + y);
} else {
System.out.println(x + y - 12);
}
sc.close();
}
}
posted:
last update: