Strings are equal impossible 1480

Title Description

No more than two lengths 80 of string, including string uppercase, lowercase, and space characters, spaces and removed after ignoring the case, determining whether two strings are equal.

Enter a description

The first input line is a set of n number of test data, each set of test data over two lines, the first line is the first string s1, the second row is the second string s2

Output Description

If the two strings are equal, the output YES, otherwise output NO

Sample input

2
a A bb BB ccc CCC
Aa BBbb CCCccc
a      dfadf     fasdf
adasddfsfsaf

Sample Output

YES

NO

thought:

Note cin space requirements, require getchar () or directly getline ()

Note that when the end of the string is represented by an array of '\ 0'

String function strcmp (), when the output is equal to 0

 1 #include<iostream>
 2 #include<string.h>
 3 #include<string>
 4 using namespace std;
 5 int main(){
 6     int n,i;
 7     cin>>n;
 8     getchar();
 9     for(i=0;i<n;i++){
10         int l1,l2,j,k;
11         char a[2][80],b[2][80],p[80];
12         for(j=0;j<2;j++){
13             gets(p);
14             strcpy(a[j],p);
15         }
16         l1=strlen(a[0]);
17         l2=strlen(a[1]);
18         k=0;
19         for(j=0;j<l1;j++){
20             if(a[0][j]>='A'&&a[0][j]<='Z'){
21                 a[0][j]=a[0][j]+32;
22             }
23         }
24         for(j=0;j<l2;j++){
25             if(a[1][j]>='A'&&a[1][j]<='Z'){
26                 a[1][j]=a[1][j]+32;
27             }
28         }
29           for(j=0;j<l1;j++){
30             if(a[0][j]!=' '){
31                 b[0][k++]=a[0][j];
32             }
33         }
34           b[0][k]='\0';
35         k=0;
36           for(j=0;j<l2;j++){
37             if(a[1][j]!=' '){
38                 b[1][k++]=a[1][j];
39             }
40         }
41           b[1][k]='\0';
42           if(strcmp(b[0],b[1])==0){
43               printf("YES\n");
44         }else{
45             printf("NO\n");
46         }    
47     }
48     return 0;
49 }

 

Guess you like

Origin www.cnblogs.com/zq-dmhy/p/11084529.html