#abc217a. A - Lexicographic Order
A - Lexicographic Order
Score : points
问题描述
你将获得两个不同的字符串 和 。
若 在字典序上小于 ,则输出 Yes
;否则,输出 No
。
什么是字典序?
简单来说,字典序就是单词在字典中排列的顺序。更形式化的定义是,以下是确定不同字符串 和 之间的字典序的算法。
以下,用 表示 的第 个字符。另外,如果 字典序上小于 ,我们记为 ;如果 字典序上大于 ,我们记为 。
- 设 为 和 长度中的较小值。对于每个 ,检查 和 是否相同。
- 如果存在某个 使得 ,令 为满足条件的最小 值。然后比较 和 。若 在字母表顺序上早于 ,则确定 并结束比较;若 晚于 ,则确定 并结束比较。
- 如果不存在使 的 ,则比较 和 的长度。若 比 短,则确定 并结束比较;若 比 长,则确定 并结束比较。
请注意,许多主流编程语言在其标准库中实现了字符串的字典序比较作为运算符或函数。有关更多细节,请参阅您所使用的语言的参考文档。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given two different strings and .
If is lexicographically smaller than , 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 and .
Below, let denote the -th character of . Also, if is lexicographically smaller than , we will denote that fact as ; if is lexicographically larger than , we will denote that fact as .
- Let be the smaller of the lengths of and . For each , we check whether and are the same.
- If there is an such that , let be the smallest such . Then, we compare and . If comes earlier than in alphabetical order, we determine that and quit; if comes later than , we determine that and quit.
- If there is no such that , we compare the lengths of and . If is shorter than , we determine that and quit; if is longer than , we determine that 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
- and are different strings, each of which consists of lowercase English letters and has a length of between and (inclusive).
Input
Input is given from Standard Input in the following format:
Output
If is lexicographically smaller than , 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