Codeforces习题 112A Petya and Strings

发布于 / 技术 / 0 条评论

这个题目就是说,在不考虑大小写的情况下比较两个字母,如果大于输出1,小于输出-1,等于输出0。

贴代码:

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.

本网站在未特殊说明的情况下采用知识共享署名-非商业性使用-相同方式共享 3.0 协议进行许可。
<-数据丢失->