Official

A - Tomorrow Editorial by en_translator


For beginners
  • If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
  • Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
  • 競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.

The answer is:

  • year \(y+1\), month \(1\), day \(1\) if year \(y\), month \(m\), day \(d\) is the last day of a year
  • year \(y\), month \(m+1\), day \(1\) if year \(y\), month \(m\), day \(d\) is the last day of a month, but not of a year
  • year \(y\), month \(m\), day \(d+1\) if year \(y\), month \(m\), day \(d\) is not the last day of a month

Use an if statement to check which of them the given date is.

Sample code (Python)

M, D = map(int,input().split())
y, m, d = map(int,input().split())

if d == D and m == M:
  print(y+1, 1, 1)
elif d == D:
  print(y, m+1, 1)
else:
  print(y, m, d+1)

Sample code (C++)

#include<bits/stdc++.h>
using namespace std;

int main(){
  int M, D, y, m, d;
  cin >> M >> D >> y >> m >> d;
  if(m==M && d==D){
    cout << y+1 << ' ' << 1 << ' ' << 1 << endl;
  }else if(d==D){
    cout << y << ' ' << m+1 << ' ' << 1 << endl;
  }else{
    cout << y << ' ' << m << ' ' << d+1 << endl;
  }
}

posted:
last update: