A - Daily Cookie 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).
This problem can be divided into the following two parts:
- Count the number of occurrences of
@
in \(S\). (Let \(A\) be this count.) - Evaluate \(N-S+D\) and print it.
Step 1 can be achieved with a loop structure (like a for
statement) and a conditional branch (like an if
statement); step 2 can be done with simple arithmetic operations.
For more details on implementation, please refer to the sample code below (C++ and Python).
Sample code (C++) :
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
string s;
cin >> n >> d >> s;
int a = 0;
for (char c: s) {
if (c == '@') ++a;
}
cout << n - a + d << endl;
}
Sample code (Python) :
n, d = map(int, input().split())
s = input()
a = 0
for c in s:
if c == '@':
a += 1
print(n - a + d)
posted:
last update: