比较字符串大小,但比较的规则不同字典序规则。字符比较新规则如下:A
输入数据包含多个测试实例,每个测试实例占两行,每一行有一个字符串(只包含大小写字母, 长度小于10000)。
如果第一个字符串小于第二个,输出YES,否则,输出NO。 注意:A
abcBbcAbaABcefABce
YESYESNO
tips:
1 不是一般的比较规则要跳出常规的眼光
2 观察找规律,总体按照 a b c d等顺序(暂时先不看大小写),可以把单个字符看做是与 a 或 A的距离
3 按照ASII码 A #include#includeint main(){char buf1[10001], buf2[10001];int len1, len2,len;double num1, num2; //数字化表示的结果while (scanf("%s%s",buf1,buf2)!&#61;EOF){len1 &#61; strlen(buf1);len2 &#61; strlen(buf2);len &#61; len1 > len2 ? len1 : len2;for (int i &#61; 0; i &#61; &#39;A&#39;&&buf1[i] <&#61; &#39;Z&#39;){num1 &#61; (int)(buf1[i] - &#39;A&#39;)-0.5;}else if (buf1[i]>&#61;&#39;a&#39;&&buf1[i]<&#61;&#39;z&#39;){num1 &#61; (int)(buf1[i] - &#39;a&#39;);}else{num1 &#61; -1; //比较到了 &#39;\0&#39; ,结果应该是NO ,故第一个应大于第二个数字}if (buf2[i] >&#61; &#39;A&#39;&&buf2[i] <&#61; &#39;Z&#39;){num2 &#61; (int)(buf2[i] - &#39;A&#39;) - 0.5;}else if (buf2[i] >&#61; &#39;a&#39;&&buf2[i] <&#61; &#39;z&#39;){num2 &#61; (int)(buf2[i] - &#39;a&#39;);}else{num2 &#61; -2; //比较到了 &#39;\0&#39;,结果应该是NO,故第二个应该小于第一个数字}if (num1num2){printf("NO\n");break;}}memset(buf1, &#39;\0&#39;, 10001);memset(buf2, &#39;\0&#39;, 10001);}}
#include#includeint main(){char buf1[10001], buf2[10001];int len1, len2,len;double num1, num2; //数字化表示的结果while (scanf("%s%s",buf1,buf2)!&#61;EOF){len1 &#61; strlen(buf1);len2 &#61; strlen(buf2);len &#61; len1 > len2 ? len1 : len2;for (int i &#61; 0; i &#61; &#39;A&#39;&&buf1[i] <&#61; &#39;Z&#39;){num1 &#61; (int)(buf1[i] - &#39;A&#39;)-0.5;}else if (buf1[i]>&#61;&#39;a&#39;&&buf1[i]<&#61;&#39;z&#39;){num1 &#61; (int)(buf1[i] - &#39;a&#39;);}else{num1 &#61; -1; //比较到了 &#39;\0&#39; ,结果应该是NO ,故第一个应大于第二个数字}if (buf2[i] >&#61; &#39;A&#39;&&buf2[i] <&#61; &#39;Z&#39;){num2 &#61; (int)(buf2[i] - &#39;A&#39;) - 0.5;}else if (buf2[i] >&#61; &#39;a&#39;&&buf2[i] <&#61; &#39;z&#39;){num2 &#61; (int)(buf2[i] - &#39;a&#39;);}else{num2 &#61; -2; //比较到了 &#39;\0&#39;,结果应该是NO,故第二个应该小于第一个数字}if (num1num2){printf("NO\n");break;}}memset(buf1, &#39;\0&#39;, 10001);memset(buf2, &#39;\0&#39;, 10001);}}