找规律:String Change
来源:互联网 发布:尔雅网络课程登陆 编辑:程序博客网 时间:2024/05/22 11:48
String change
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 370 Accepted Submission(s): 166
Problem Description
In this problem you will receive two strings S1 and S2 that contain only lowercase letters.
Each time you can swap any two characters of S1. 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 S1 as many times as you want.
Please tell us whether you can change S1 to S2 after some operations or not.
Each time you can swap any two characters of S1. 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 S1 as many times as you want.
Please tell us whether you can change S1 to S2 after 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 S1,the second line is S2.S1 has the same length as S2 and the length of the string is between 2 and 60.
For each case,the first line is S1,the second line is S2.S1 has the same length as S2 and 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 S1 to S2 output "YES",otherwise output "NO".
Sample Input
3abbabacddbaaabbcbccd
Sample Output
Case #1: NOCase #2: YESCase #3: YESHintFor the first case,it's impossible to change "ab" to "ba" .For the second case,swap(S1[0],S1[2])->swap(S1[1],S1[2]),meanwhile:bac->dac->ddb.For the third case,swap(S1[0],S1[3])->swap(S1[1],S1[2])->swap(S1[2],S1[3])->swap(S1[3],S1[4]),meanwhile:aaabb->caabb->cbbbb->cbccb->cbccd.
Author
miketc@UESTC_Goldfinger
Source
2012 Multi-University Training Contest 6
这个题完全是找规律= =。
当长度为2的时候特判一下,其他长度如果同奇偶就YES,否则NO
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;char str1[70], str2[70];int num1[70], num2[70];int main(){ int t; int cnt = 0; scanf("%d", &t); while(t --){ cnt ++; scanf("%s %s", str1, str2); int len = strlen(str1); for(int i = 0; i < len; i ++){ num1[i] = str1[i] - 'a' + 1; num2[i] = str2[i] - 'a' + 1; } printf("Case #%d: ", cnt); if(len == 2){ if(num1[0] - num2[0] == num1[1] - num2[1] && (num1[0] - num2[0]) % 2 == 0) printf("YES\n"); else if(num1[0] - num2[1] == num1[1] - num2[0] && (int)abs((float)num1[0] - (float)num2[1]) % 2) printf("YES\n"); else printf("NO\n"); } else{ int sum = 0; for(int i = 0; i < len; i ++){ sum += num1[i] - num2[i]; } if((int)abs((sum)) % 2 == 0) printf("YES\n"); else printf("NO\n"); } } return 0;}
- 找规律:String Change
- [规律] hdu 4357 string change
- hdoj 2277 Change the ball 【找规律】
- hdu 2277 Change the ball(找规律)
- hdoj 2277 Change the ball 【找规律】
- hdoj 2277 Change the ball 【找规律】
- TOJ3976 Change 完全背包 || 找规律
- HDU 4357 String change 规律题
- 【杭电oj】2277 - Change the ball(找规律)
- HDU 2277 Change the ball(找规律)
- TOJ 3976.Change(dp或找规律)
- UVALive - 6832 Bit String Reordering (找规律)
- HDU5694-BD String-数学归纳找规律
- 找规律
- 找规律!
- 找规律
- 找规律,
- 找规律
- vim删除^M
- cocos2dx(7)
- 如何使用W7100A实现网络字符LCD(二)
- 今天真懂了,为啥许多公司不重视数据分析
- 线性表
- 找规律:String Change
- SQL Server 2008查看死锁的存储过程的代码示例
- Java 获取当前线程的相关信息
- #java与c#通信
- Loadrunner日志设置与查看
- cocos2dx(8)
- cocos2dx(9)
- 20大UI设计原则——优秀设计师必备
- PHP超时处理全面总结