Official

A - Chompers Editorial by en_translator


For beginners

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: