Official

A - Chompers Editorial by sheyasutaka


初心者の方へ

実装方針

C++, Python を含む多くの主流な言語では,ある文字列の部分文字列をとる関数が標準で用意されています.その仕様にしたがって実装するのが簡潔です.

たとえば Python では s[i:j] によって,0-indexed で \(i\) 文字目以上 \(j\) 文字目未満の範囲を取得できます.

一方で C++ では s.substr(i, x) によって,0-indexed で \(i\) 文字目からはじめて長さ \(x\) の範囲を取得できます.

実装例 (Python3, C++)

Python3 での実装例を以下に示します.

s = input()
n = int(input())

ans = s[n:(len(s) - n)]

print(ans)

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: