Official
A - Chompers 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.
Implementation approach
Most major languages including C++ and Python have a function to extract a substring of a string, so it is clever to follow its specification.
For example, in Python s[i:j] yields the substring formed by the \(i\)-th (inclusive) to \(j\)-th (exclusive) characters, in zero-based indexing.
Meanwhile, in C++ s.substr(i, x) yields the substring starting from the \(i\)-th character, in zero-based indexing, of length \(x\).
Sample code (Python 3, C++)
The following is sample code in Python 3.
s = input()
n = int(input())
ans = s[n:(len(s) - n)]
print(ans)
The following is sample code in C++.
#include <iostream>
using std::cin;
using std::cout;
#include <string>
using std::string;
int main (void) {
string s;
int n;
cin >> s;
cin >> n;
string ans = s.substr(n, s.size() - n*2);
cout << ans << "\n";
return 0;
}
posted:
last update: