Official

A - wwwvvvvvv Editorial by en_translator


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” (https://atcoder.jp/contests/abs).


In this problem can be solved by using a for statement to implement the following process:

  • for each character \(c\) in \(S\),
    • if \(c\) is v, add \(1\) to the answer;
    • if \(c\) is w, add \(2\) to the answer.

Many languages have a feature to “inspect each element of a string or an array;” In C++, such a feature is called a ranged for statement. (It is also called a foreach statement.)

The following is a sample code in C++ and Python.

C++

#include<bits/stdc++.h>

using namespace std;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (char c: s) {
        if (c == 'v') {
            ans += 1;
        } else {
            ans += 2;
        }
    }
    cout << ans << endl;
}

Python

s = input()

ans = 0
for c in s:
    if c == 'v':
        ans += 1
    else:
        ans += 2
        
print(ans)

posted:
last update: