【ECJTU_ACM 11级队员2012年暑假训练赛(8) - H - Petya and Strings】

本博客介绍了一道关于字符串比较的问题,通过将输入的两个字符串进行大小写转换后进行字典顺序比较,并输出比较结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B题要套一个数论的模版,注意m=1!! C题可以二分匹配,把行列看作点; 不能开百度,开谷歌搜题解,再次强调!一经发现,取消成绩!

ECJTU_ACM 11级队员2012年暑假训练赛(8)
4:30:00
 
 
A  B  C  D  E  F  G  H  I  J  K
H - Petya and Strings
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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.

Sample Input

Input
aaaa
aaaA
Output
0
Input
abs
Abz
Output
-1
Input
abcdefg
AbCdEfF
Output
1

Hint

If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:

 

  • http://en.wikipedia.org/wiki/Lexicographical_order

 


FAQ | About Virtual Judge |  Forum |  Discuss |  Open Source Project
All Copyright Reserved ©2010-2012  HUST ACM/ICPC TEAM 
Anything about the OJ, please ask in the  forum, or contact author: Isun
Server Time: 

 

 

 

 1 // Project name : H ( Petya and Strings ) 
 2 // File name    : main.cpp
 3 // Author       : iCoding
 4 // E-mail       : honi.linux@gmail.com
 5 // Date & Time  : Fri Aug 10 13:14:48 2012
 6 
 7 
 8 #include <iostream>
 9 #include <stdio.h>
10 #include <string>
11 #include <cmath>
12 #include <algorithm>
13 using namespace std;
14 
15 /*************************************************************************************/
16 /* data */
17 string sa, sb;
18 
19 /*************************************************************************************/
20 /* procedure */
21 
22 int iCalForResult()
23 {
24     int iTop = sa.length() - 1;
25     for (int i = 0; i <= iTop; i++)
26     {
27         if (sa[i] >= 'A' && sa[i] <= 'Z')
28         {
29             sa[i] += 32;
30         }
31         if (sb[i] >= 'A' && sb[i] <= 'Z')
32         {
33             sb[i] += 32;
34         }
35     }
36 
37     int res = 0;
38     for (int i = 0; res == 0 && i <= iTop; i++)
39     {
40         if (sa[i] > sb[i])
41         {
42             res = 1;
43         }
44         else if (sa[i] < sb[i])
45         {
46             res = -1;
47         }
48     }
49     return res;
50 }
51 /*************************************************************************************/
52 /* main */
53 int main()
54 {
55     while (cin >> sa >>sb)
56     {
57         cout << iCalForResult() << endl;
58     }
59     return 0;
60 }
61 
62 // end 
63 // Code by Sublime text 2
64 // iCoding@CodeLab 

转载于:https://www.cnblogs.com/ismdeep/archive/2012/08/13/2635986.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值