Official
A - Chompers Editorial
by
A - Chompers Editorial
by
sheyasutaka
初心者の方へ
- プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは practice contest の問題A「Welcome to AtCoder」をお試しください。言語ごとに解答例が掲載されています。
- また、プログラミングコンテストの問題に慣れていない方は、 AtCoder Beginners Selection の問題をいくつか試すことをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
- Python入門 AtCoder Programming Guide for beginners (APG4bPython) は、競技プログラミングのための Python 入門用コンテンツです。
実装方針
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:
