Official
A - First Contest of the Year Editorial
by
A - First Contest of the Year Editorial
by
cn449
初心者の方へ
- プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは practice contest の問題A「Welcome to AtCoder」をお試しください。言語ごとに解答例が掲載されています。
- また、プログラミングコンテストの問題に慣れていない方は、 AtCoder Beginners Selection の問題をいくつか試すことをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
- Python入門 AtCoder Programming Guide for beginners (APG4bPython) は、競技プログラミングのための Python 入門用コンテンツです。
ある年の最初のコンテストが \(F\) 日目に開催されるとき、その年には \(F, F + 7, F + 14, \ldots\) 日目にコンテストが開催されます。
次の年の \(x\) 日目が「ある年」の \(D + x\) 日目に相当することを考えると、\(F\) が \(D\) 以下である間 \(F\) に \(7\) を加算し続け、\(F - D\) を出力すると答えとなります。この操作は while 文などを用いると実現できます。
実装例
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, f;
cin >> d >> f;
while (f <= d) f += 7;
cout << f - d << '\n';
}
また、以下のようにループを用いずに答えを出すことも可能です。
実装例
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, f;
cin >> d >> f;
cout << 7 - ((d - f) % 7) << '\n';
}
posted:
last update: