Official
A - September 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".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
This problem requires a usage of for
statement and a retrieval of the length of a string.
One can use a for
statement to repeat the following operation for \(i=1,2,\ldots 12\):
- Read a string.
- If its length equals \(i\), add \(1\) to the answer.
When implementing, you need to use an appropriate function for string length retrieval provided by your programming language.
In C++, a string type is represented by std::string
; for a std::string s
, its length can be obtained as s.size()
.
In Python, the length of s
can be obtained as len(s)
.
Sample code (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
for (int i = 1; i <= 12; ++i) {
string s;
cin >> s; // Read string s
if ((int)s.size() == i) { // Check if its length equals i
ans++; // If so, add 1 to the answer
}
}
cout << ans << endl;
}
Sample codde (Python3):
ans = 0
for i in range(1, 12 + 1):
s = input() # Read string s
if len(s) == i: # Check if its length equals i
ans += 1 # If so, add 1 to the answer
print(ans)
posted:
last update: