Official

A - Lexicographic Order Editorial by en_translator


This problem asks how to compare strings lexicographically.

One can implement an algorithm to compare strings, but as mentioned in the problem statement, many programming languages have functions that compare strings in their standard libraries, so it is much easier to use them. If you do not know how to compare strings in your language, learn it from the references of the language.

The following is the sample codes in C, C++, and 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: