Official

A - Lexicographic Order Editorial by Nyaan


この問題は文字列を辞書順比較する方法を聞いている問題です。

文字列同士を比較するアルゴリズムを実装しても AC することはできますが、問題文にもある通り、多くのプログラミング言語では文字列比較を行う関数は標準ライブラリに実装されているのでそちらを使う方が簡明です。もしも自分の使っている言語で文字列を比較する方法がわからない場合は、各言語のリファレンスを参照するなどして勉強してみましょう。

C, C++, Python における実装例は以下の通りです。

  • C
#include <stdio.h>
#include <string.h>
char S[32], T[32];

int main() {
  scanf("%s %s", S, T);
  if (strcmp(S, T) < 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}
  • C++
#include <iostream>
#include <string>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  cout << (S < T ? "Yes" : "No") << endl;
}
  • Python
S, T = input().split()
print("Yes" if S < T else "No")

posted:
last update: