xtu oj 1037

#include <stdio.h>
#include <string.h>
int main()
{
 int n,i,flag,l;
 int str[1000];
 char ch[1111];
 scanf("%d",&n);
 while(n--)
 {
  scanf("%s",ch);
  memset(str,0,sizeof(str));// 先全部初始化。
  l=strlen(ch);
  i=0;
  if(l%2!=0)//奇数不符合
  {
  printf("No\n");
  continue;//防止输出两个
     }
     flag=0;
  while(i<l)//条件
  {
   if(str[ch[i]]==0)
   {
   str[ch[i]]=i+1;//计算所在的位置
      }
   else
   {
    if((i-str[ch[i]])%2==0)//每次只一共计算两个值
    {
    flag=flag+2;
    str[ch[i]]==0;//相隔如果两个同时是偶数则不行。
    }//奇数之间间隔的必为奇数不行。
   }
   i++; //i++;枚举
    }
   if(flag==l)//全部枚举完即符合
   printf("Yes\n");
   else
   printf("No\n");
 }
 

Description

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


输入:

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


输出:

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

 

Sample Input

2 
aAbbAaaabbcc
abcdefghijklmn
 

Sample Output

Yes
No
 

Source

程序设计实践
 

Hint

字符串只有英文字母,大小写敏感。
 
[ Submit Code ] [ Top 20 Runs ] [ Runs Status ]
 
 


 return 0;
}

猜你喜欢

转载自www.cnblogs.com/kyx599/p/11980102.html