Description |
||
有些字符串,如果满足下面的性质,则称为成对的字符串:
第一行是一个整数K,表示有多少个测试用例,以后每行一个测试用例。每行为一个字符串(长度不超过1000个字符)。
每行输出一个测试用例的结果。如果是,输出Yes,否则输出No。 |
||
Sample Input |
||
2 aAbbAaaabbcc abcdefghijklmn |
||
Sample Output |
||
Yes No |
||
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 int main(){ 4 char str[1000]; 5 char array[1000]; 6 int num[1000]; 7 int flag; 8 int i,j,t,x,n; 9 scanf("%d",&n); 10 while(n--){ 11 flag=1; 12 scanf("%s",&str); 13 // initial num[] with 0 14 memset(num,0,1000); 15 array[0]=str[0]; 16 // count the number of same char 17 t=0; 18 num[0]=1; 19 for(i=1;str[i]!='\0';i++){ 20 //associate element from str[] to array[] 21 for(j=0;j<=t;j++){ 22 // select elements from str[] and array respectivly, if they are equal then do 23 if(str[i]==array[j]){ 24 // check the number of same element 25 for(x=t;x>j;x--){ 26 if(num[x]%2!=0){ 27 flag=0; 28 break; 29 } 30 } 31 num[j]++; 32 break; 33 } 34 if(!flag) 35 break; 36 } 37 if(j>t){ 38 t=t+1; 39 array[t]=str[i]; 40 num[t]++; 41 } 42 if(!flag) 43 break; 44 } 45 // if the number of anyone element is odd, the result is No 46 for(i=0;i<=t;i++) 47 if(num[i]%2!=0){ 48 flag=0; 49 break; 50 } 51 if(flag) 52 printf("Yes\n"); 53 else 54 printf("No\n"); 55 } 56 return 0; 57 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 int main(){ 4 char str[1000]; 5 char array[1000]; 6 int num[1000]; 7 int flag; 8 int i,j,t,x,n; 9 scanf("%d",&n); 10 while(n--){ 11 flag=1; 12 scanf("%s",&str); 13 // initial num[] with 0 14 memset(num,0,1000); 15 array[0]=str[0]; 16 // count the number of same char 17 t=0; 18 num[0]=1; 19 for(i=1;str[i]!='\0';i++){ 20 //associate element from str[] to array[] 21 for(j=0;j<=t;j++){ 22 // select elements from str[] and array respectivly, if they are equal then do 23 if(str[i]==array[j]){ 24 // check the number of same element 25 for(x=t;x>j;x--){ 26 if(num[x]%2!=0){ 27 flag=0; 28 break; 29 } 30 } 31 num[j]++; 32 break; 33 } 34 if(!flag) 35 break; 36 } 37 if(j>t){ 38 t=t+1; 39 array[t]=str[i]; 40 num[t]++; 41 } 42 if(!flag) 43 break; 44 } 45 // if the number of anyone element is odd, the result is No 46 for(i=0;i<=t;i++) 47 if(num[i]%2!=0){ 48 flag=0; 49 break; 50 } 51 if(flag) 52 printf("Yes\n"); 53 else 54 printf("No\n"); 55 } 56 return 0; 57 }