Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <string.h>
- using namespace std;
- int perm[30];
- int cycle[30];
- int _42;
- bool mark[30];
- int main() {
- scanf("%d", &_42);
- while (_42--) {
- char tmp[30];
- scanf(" %s", tmp);
- memset(mark,false,sizeof(mark));
- memset(cycle,0,sizeof(cycle));
- for (int i=0; i<26; i++)
- perm[i]=tmp[i]-'A';
- for (int i=0; i<26; i++)
- if (!mark[i]) {
- int cnt=0, pos=i;
- while (!mark[pos]) {
- mark[pos]=true, cnt++;
- pos=perm[pos];
- }
- cycle[cnt]++;
- }
- bool can=true;
- for (int i=1; i<=26; i++)
- if (i%2==0 && cycle[i]%2)
- can=false;
- printf("%s\n", can? "Yes":"No");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement