成对的字符串

Description

有些字符串,如果满足下面的性质,则称为成对的字符串:
a. 所有的字符在字符串中出现偶数次
b. 每一对相同的字符之间不会有出现奇数次的字符
现在给你一些字符串,请判断这些字符串是否为成对的字符串。


输入:

第一行是一个整数K,表示有多少个测试用例,以后每行一个测试用例。每行为一个字符串(长度不超过1000个字符)。


输出:

每行输出一个测试用例的结果。如果是,输出Yes,否则输出No。

 

Sample Input

2 
aAbbAaaabbcc
abcdefghijklmn
 

Sample Output

Yes
No
 
 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 }
View Code
 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 }
View Code

 

转载于:https://www.cnblogs.com/hoojjack/p/5384716.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值