#abc217a. A - Lexicographic Order

A - Lexicographic Order

Score : 100100 points

问题描述

你将获得两个不同的字符串 SSTT
SS 在字典序上小于 TT,则输出 Yes;否则,输出 No

什么是字典序?

简单来说,字典序就是单词在字典中排列的顺序。更形式化的定义是,以下是确定不同字符串 SSTT 之间的字典序的算法。

以下,用 SiS_i 表示 SS 的第 ii 个字符。另外,如果 SS 字典序上小于 TT,我们记为 S<TS \lt T;如果 SS 字典序上大于 TT,我们记为 S>TS \gt T

  1. LLSSTT 长度中的较小值。对于每个 i=1,2,,Li=1,2,\dots,L,检查 SiS_iTiT_i 是否相同。
  2. 如果存在某个 ii 使得 SiTiS_i \neq T_i,令 jj 为满足条件的最小 ii 值。然后比较 SjS_jTjT_j。若 SjS_j 在字母表顺序上早于 TjT_j,则确定 S<TS \lt T 并结束比较;若 SjS_j 晚于 TjT_j,则确定 S>TS \gt T 并结束比较。
  3. 如果不存在使 SiTiS_i \neq T_iii,则比较 SSTT 的长度。若 SSTT 短,则确定 S<TS \lt T 并结束比较;若 SSTT 长,则确定 S>TS \gt T 并结束比较。

请注意,许多主流编程语言在其标准库中实现了字符串的字典序比较作为运算符或函数。有关更多细节,请参阅您所使用的语言的参考文档。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given two different strings SS and TT.
If SS is lexicographically smaller than TT, print Yes; otherwise, print No.

What is the lexicographical order?

Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings SS and TT.

Below, let SiS_i denote the ii-th character of SS. Also, if SS is lexicographically smaller than TT, we will denote that fact as S<TS \lt T; if SS is lexicographically larger than TT, we will denote that fact as S>TS \gt T.

  1. Let LL be the smaller of the lengths of SS and TT. For each i=1,2,,Li=1,2,\dots,L, we check whether SiS_i and TiT_i are the same.
  2. If there is an ii such that SiTiS_i \neq T_i, let jj be the smallest such ii. Then, we compare SjS_j and TjT_j. If SjS_j comes earlier than TjT_j in alphabetical order, we determine that S<TS \lt T and quit; if SjS_j comes later than TjT_j, we determine that S>TS \gt T and quit.
  3. If there is no ii such that SiTiS_i \neq T_i, we compare the lengths of SS and TT. If SS is shorter than TT, we determine that S<TS \lt T and quit; if SS is longer than TT, we determine that S>TS \gt T and quit.

Note that many major programming languages implement lexicographical comparison of strings as operators or functions in standard libraries. For more detail, see your language's reference.

Constraints

  • SS and TT are different strings, each of which consists of lowercase English letters and has a length of between 11 and 1010 (inclusive).

Input

Input is given from Standard Input in the following format:

SS TT

Output

If SS is lexicographically smaller than TT, print Yes; otherwise, print No.

Sample Input 1

abc atcoder

Sample Output 1

Yes

abc and atcoder begin with the same character, but their second characters are different. Since b comes earlier than t in alphabetical order, we can see that abc is lexicographically smaller than atcoder.

Sample Input 2

arc agc

Sample Output 2

No

Sample Input 3

a aa

Sample Output 3

Yes

update @ 2024/3/10 09:36:22