Official

A - September Editorial by en_translator


For beginners

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: