公式

A - Takahashi san 2 解説 by en_translator


Extract the substring formed by the last three characters of the given string. If it coincides with saw, print Yes; otherwise, print No.
One can extract the substring as a notation of a standard library in C++ and Python.

Alternatively, for the length of string \(N\), the condition in the problem is equivalent to: “the \((N-2)\)-th character of \(S\) is s,” “the \((N-1)\)-th character of \(S\) is a,” and “the \(N\)-th character of \(S\) is n.” One can use this too.

Sample code in C++:

#include <bits/stdc++.h>

using namespace std;

int main() {
	string s;
	
	cin >> s;
	if(s.substr(s.size() - 3)=="san")cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Sample code in Python:

s=input()
if s[-3:]=="san":
    print("Yes")
else:
    print("No")

投稿日時:
最終更新: