Official
A - N-choice question 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.
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
What you have to do in this problem is:
- receive the input from the Standard Input;
- find \(A+B\);
- find the index of the correct choice; and
- print the answer to the Standard Output.
If you have trouble in the first and fourth, you can learn in the following way:
- read the document of or article on your programming language;
- view other contestant’s code in “all submissions” to learn how to input and output.
The second can be achieved by adding variables.
The third can be achieved with a for loop. Inspect the choice one by one, and store its index once you find the answer.
Sample code (C++):
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b;
cin >> n >> a >> b;
vector<int> c(n);
for(auto &nx : c){cin >> nx;}
int ans;
for(int i=0;i<n;i++){
if(a+b == c[i]){ans=i+1;break;}
}
cout << ans << "\n";
return 0;
}
posted:
last update: