A - o-padding 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).
Basically, all you need is to implement what is described in the problem statement. There are two possible implementation approach:
- Use a loop structure like a
forloop to print \((N - |S|)\) copies ofo, and then \(S\). - Create a string \(T\) that is a \((N-|S|)\)-time repetition of
o, and print \(T\) and \(S\) in this order.
Although approach 2 may seems slightly tedious, languages like C++ and Python has a built-in feature that can create a string repeated specific times, which makes your implementation concise. For more details, please refer to the following sample code (C++ and Python):
Sample code of approach 1 (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
for (int i = 0; i < n - s.size(); i++) {
cout << 'o';
}
cout << s << endl;
}
Sample code of approach 1 (Python):
n = int(input())
s = input()
for i in range(n - len(s)):
print('o', end='')
print(s)
Sample code of approach 2 (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
string t(n - s.size(), 'o');
cout << t << s << endl;
}
Sample code of approach 2 (Python):
n = int(input())
s = input()
t = 'o' * (n - len(s))
print(t + s)
posted:
last update: