公式

A - Strong Word 解説 by KumaTachiRen


\(S\) の先頭の文字と末尾の文字を比較すればよいです。

文字列の先頭および末尾の文字を取得する方法は言語によって異なり、また同じ言語でも複数の方法が考えられます。以下に C++, Python の解答例を示します。

#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    if (S.front() == S.back()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
S = input()
if S[0] == S[-1]:
    print("Yes")
else:
    print("No")

投稿日時:
最終更新: