如何通过巧妙变换实现字符串的hdu 4357 String change?

2026-04-19 23:242阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计649个文字,预计阅读时间需要3分钟。

如何通过巧妙变换实现字符串的hdu 4357 String change?

字符串+时间限制:2000/1000毫秒(Java/其他)内存限制:65536/32768K(Java/其他)总提交次数:802接受提交次数:370题目描述:在这个问题中,你将接收到两个只包含小写字母的字符串S1和S2。

String change

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 802Accepted Submission(s): 370

Problem Description

In this problem you will receive two strings S 1and S 2that contain only lowercase letters. Each time you can swap any two characters of S 1. After swap,both of the two letters will increase their value by one. If the previous letter is 'z',it will become 'a' after being swapped. That is to say ,"a" becomes "b","b" becomes "c"....."z" becomes "a" and so on. You can do the change operation in S 1as many times as you want. Please tell us whether you can change S 1to S 2after some operations or not.

Input

There are several cases.The first line of the input is a single integer T (T <= 41) which is the number of test cases.Then comes the T test cases . For each case,the first line is S 1,the second line is S 2.S 1has the same length as S 2and the length of the string is between 2 and 60.

Output

For each case,output "Case #X: " first, X is the case number starting from 1.If it is possible change S 1to S 2output "YES",otherwise output "NO".

Sample Input

3abbabacddbaaabbcbccd

Sample Output

Hint

Author

miketc@UESTC_Goldfinger

如何通过巧妙变换实现字符串的hdu 4357 String change?

Source

​​2012 Multi-University Training Contest 6​​

Recommend

zhuyuanchen520

思路:推理后发现超过两张牌的情况,只要是奇偶一样都可以用变换。

#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int mm=99;char s[mm],t[mm];int cas;int main(){ while(~scanf("%d",&cas)) { for(int ca=1;ca<=cas;++ca) { scanf("%s%s",s,t); printf("Case #%d: ",ca); int len=strlen(s); bool a=0,b=0; bool flag=0; int k1,k2; if(len==2) { k1=(s[0]-t[0]+26)%26; k2=(s[1]-t[1]+26)%26; if(k1==k2&&k1%2==0)flag=1; k1=(s[0]-t[1]+26)%26; k2=(s[1]-t[0]+26)%26; if(k1==k2&&k1%2==1)flag=1; if(flag)printf("YES\n"); else printf("NO\n"); } else { for(int i=0;i<len;++i) { a^=s[i]&1; b^=t[i]&1; } if(a==b)printf("YES\n"); else printf("NO\n"); } } } return 0;}

本文共计649个文字,预计阅读时间需要3分钟。

如何通过巧妙变换实现字符串的hdu 4357 String change?

字符串+时间限制:2000/1000毫秒(Java/其他)内存限制:65536/32768K(Java/其他)总提交次数:802接受提交次数:370题目描述:在这个问题中,你将接收到两个只包含小写字母的字符串S1和S2。

String change

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 802Accepted Submission(s): 370

Problem Description

In this problem you will receive two strings S 1and S 2that contain only lowercase letters. Each time you can swap any two characters of S 1. After swap,both of the two letters will increase their value by one. If the previous letter is 'z',it will become 'a' after being swapped. That is to say ,"a" becomes "b","b" becomes "c"....."z" becomes "a" and so on. You can do the change operation in S 1as many times as you want. Please tell us whether you can change S 1to S 2after some operations or not.

Input

There are several cases.The first line of the input is a single integer T (T <= 41) which is the number of test cases.Then comes the T test cases . For each case,the first line is S 1,the second line is S 2.S 1has the same length as S 2and the length of the string is between 2 and 60.

Output

For each case,output "Case #X: " first, X is the case number starting from 1.If it is possible change S 1to S 2output "YES",otherwise output "NO".

Sample Input

3abbabacddbaaabbcbccd

Sample Output

Hint

Author

miketc@UESTC_Goldfinger

如何通过巧妙变换实现字符串的hdu 4357 String change?

Source

​​2012 Multi-University Training Contest 6​​

Recommend

zhuyuanchen520

思路:推理后发现超过两张牌的情况,只要是奇偶一样都可以用变换。

#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int mm=99;char s[mm],t[mm];int cas;int main(){ while(~scanf("%d",&cas)) { for(int ca=1;ca<=cas;++ca) { scanf("%s%s",s,t); printf("Case #%d: ",ca); int len=strlen(s); bool a=0,b=0; bool flag=0; int k1,k2; if(len==2) { k1=(s[0]-t[0]+26)%26; k2=(s[1]-t[1]+26)%26; if(k1==k2&&k1%2==0)flag=1; k1=(s[0]-t[1]+26)%26; k2=(s[1]-t[0]+26)%26; if(k1==k2&&k1%2==1)flag=1; if(flag)printf("YES\n"); else printf("NO\n"); } else { for(int i=0;i<len;++i) { a^=s[i]&1; b^=t[i]&1; } if(a==b)printf("YES\n"); else printf("NO\n"); } } } return 0;}