百练 2743 字符串判等 解题报告

链接:http://poj.grids.cn/practice/2743/

题目:

总时间限制:
1000ms
内存限制:
65536kB
描述
判断两个由大小写字母和空格组成的字符串在忽略大小写和压缩掉空格后是否相等
输入
第1行是测试数据的组数n,每组测试数据占2行,第1行是第一个字符串s1,第2行是第二个字符串s2。
每组测试数据之间有一个空行,每行数据不超过100个字符(注意字符串的长度可能为0)
输出
n行,相等则输出YES,否则输出NO
样例输入
3







a A bb BB ccc CCC

Aa BBbb CCCccc



a              dfadf              fasdf

adasddfsfsaf
样例输出
YES

YES

NO

代码:

 1 #include <iostream>

 2 #include <cstdio>

 3 #include <cstdlib>

 4 #include <cstring>

 5 using namespace std;

 6 int main()

 7 {

 8     //freopen("F:\\input.txt","r",stdin);

 9     

10     int n;

11     cin>>n;

12     //cin.get();

13     

14     char s1[200],s2[200],s3[200],s4[200];

15     while(n--)

16     {

17         gets(s1);

18         gets(s1);

19         gets(s2);

20         

21         int len1 = strlen(s1);

22         int len2 = strlen(s2);

23         

24         int idx1 = 0;

25         for(int i = 0; i < len1; i++)

26         {

27             if(s1[i] != ' ')

28             {

29                 if(s1[i] >= 'A' && s1[i] <= 'Z') s3[idx1++] = (s1[i]-'A') + 'a';

30                 else s3[idx1++] = s1[i];

31             }

32         }

33         s3[idx1] = '\0';

34         

35         idx1 = 0;

36         for(int i = 0; i < len2; i++)

37         {

38             if(s2[i] != ' ')

39             {

40                 if(s2[i] >= 'A' && s2[i] <= 'Z') s4[idx1++] = (s2[i] - 'A') + 'a';

41                 else s4[idx1++] = s2[i];

42             }

43         }

44         s4[idx1] = '\0';

45         

46         //cout<<"s3:"<<s3<<",s4:"<<s4<<endl;

47         if(strcmp(s3,s4)) cout<<"NO"<<endl;

48         else cout<<"YES"<<endl;

49     }

50     return 0;

51 }

思路:

1.注意测试实例间有空行

你可能感兴趣的:(字符串)