LoginSignup
1
1

More than 5 years have passed since last update.

解法1(愚直な方法)

  • 1989年から2019年の間かどうかを判定する。trueなら答えはまだわからない。falseなら答えはNo
  • これ以降は1989年から2019年の間の場合を考える。
  • 1989年1月8日より前なら答えはNo
  • 2019年5月以降なら答えはNo(4月は30日までしかないから5月以降の判定でOK)
  • それ以外なら答えはYes
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
  int y, m, d;
  cin >> y >> m >> d;

  if (1989 <= y && y <= 2019) {
    if (y == 1989 && m == 1) {
      if (d < 8) {
        puts("No");
        return 0;
      }
    }

    if (y == 2019 && m >= 5) {
      puts("No");
      return 0;
    }

    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}

解法2(賢い方法)

  • {1989, 1, 8}{2019, 4, 30}を作る
  • 判定する日付を{y, m, d}として格納する
  • 配列同士を比較する
#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<int> low = {1989, 1, 8};
vector<int> high = {2019, 4, 30};
vector<int> now(3);

signed main() {
  cin >> now[0] >> now[1] >> now[2];

  puts((low <= now && now <= high) ? "Yes" : "No");

  return 0;
}

メモ

  • 配列同士を比較できるの知らなかった。
  • 最初に年が判定され、年が同じなら月が判定され、月が同じなら日が判定されるって感じだと思う。
  • 文字列の比較と同じ感じ(なんか直感的にわかりづらいけど)
1
1
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1