1155: 字符串比较 多实例
题目描述
比较字符串大小,但比较的规则不同字典序规则。字符比较新规则如下:A < a < B < b < ………… < Z < z。
输入
输入数据包含多个测试实例,每个测试实例占两行,每一行有一个字符串(只包含大小写字母, 长度小于10000)。
输出
如果第一个字符串小于第二个,输出YES,否则,输出NO。
注意:A < a < B < b < ………… < Z < z。
样例输入 Copy
abc
Bbc
Ab
a
ABcef
ABce
样例输出 Copy
YES
YES
NO
来源/分类
#include<stdio.h>
#include<string.h>
#define MAX 10000
/*
字符串比较A < a < B < b < ………… < Z < z。
小写的是奇数
大写的是偶数
*/
int main(){
char str1[MAX],str2[MAX];
while(scanf("%s%s",&str1,&str2)!=EOF){
for(int i=0;str1[i]!='\0';i++){
if(str1[i]>='a'&&str1[i]<='z') {
//将小写字符改为ASKII码为1,3,5的字符
str1[i]=(str1[i]-'a')*2+1;
}
if(str1[i]>='A'&&str1[i]<='Z') {
//将小写字符改为ASKII码为0,2,4的字符
str1[i]=(str1[i]-'A')*2;
}
}
for(int i=0;str2[i]!='\0';i++){
if(str2[i]>='a'&&str2[i]<='z') {
str2[i]=(str2[i]-'a')*2+1;
}
if(str2[i]>='A'&&str2[i]<='Z') {
str2[i]=(str2[i]-'A')*2;
}
}
if(strcmp(str1,str2)<0) printf("YES\n");
else printf("NO\n");
}
return 0;
}