本文最后更新于 1209 天前,其中的信息可能已经有所发展或是发生改变。
这个题目就是说,在不考虑大小写的情况下比较两个字母,如果大于输出1,小于输出-1,等于输出0。
贴代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
StringA = str(input().lower()) StringB = str(input().lower()) LatinLOW = 'abcdefghijklmnopqrstuvwxyz' CostA = 0 CostB = 0 if StringA == StringB: print(0) else: for i in range(0,len(StringA)): CostA = LatinLOW.find(StringA[i]) CostB = LatinLOW.find(StringB[i]) if (CostA - CostB) > 0: print(1) break elif (CostA - CostB) < 0: print(-1) break |
代码已经通过codeforces自动检测。
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters’ case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Input
Each of the first two lines contains a bought string. The strings’ lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
Output
If the first string is less than the second one, print “-1”. If the second string is less than the first one, print “1”. If the strings are equal, print “0”. Note that the letters’ case is not taken into consideration when the strings are compared.