• 成对的字符串


    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]!='';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
    ");
    53     else
    54         printf("No
    ");
    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]!='';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
    ");
    53     else
    54         printf("No
    ");
    55 }
    56 return 0;
    57 }
    View Code
  • 相关阅读:
    视频聊天相关技术介绍
    block相关归纳
    block的作用
    block教程
    向appstore提交app流程
    ios xmpp 发送语音图片解决方案
    python 三元运算、列表推倒式、字典推倒式、生成器生成式
    python 生成器
    python 迭代器(第二次总结)
    python 迭代器
  • 原文地址:https://www.cnblogs.com/hoojjack/p/5384716.html
Copyright © 2020-2023  润新知