17:字符串判等

http://noi.openjudge.cn/ch0107/17/spa

全局題號1745code

總時間限制: 1000ms 內存限制: 65536kB
描述

判斷兩個由大小寫字母和空格組成的字符串在忽略大小寫,且忽略空格後是否相等。blog

輸入
兩行,每行包含一個字符串。
輸出
若兩個字符串相等,輸出YES,不然輸出NO。
樣例輸入
a A bb BB ccc CCC
Aa BBbb CCCccc
樣例輸出
YES
 1 #include<stdio.h>
 2 #include<string.h>
 3 void toUp(char a[]);//把a[]所有變爲大寫
 4 void clearSpace(char a[]);//清空a[]裏面的空格 
 5 int main()
 6 {
 7     char s1[1000],s2[1000];
 8     gets(s1);
 9     gets(s2);
10     toUp(s1);toUp(s2);
11     clearSpace(s1);
12     clearSpace(s2);
13     if(strcmp(s1,s2)==0) printf("YES");
14     else printf("NO");
15     return 0;
16 }
17 void toUp(char a[])//把a[]所有變爲大寫
18 {
19     int i;
20     for(i=0;a[i]!='\0';i++)
21     {
22         if(a[i]>='a'&&a[i]<='z') a[i]-=32;
23     }
24 }
25 void clearSpace(char a[])//清空a[]裏面的空格 
26 {
27     int i,j;
28     for(i=0,j=0;a[j]!='\0';j++)
29     {
30         if(a[j]!=' ')
31         {
32             a[i]=a[j];  i++;
33         }
34     }
35     a[i]='\0';
36 }
相關文章
相關標籤/搜索