ZCMU-1425-Careless Tony
2017-01-09 15:08
204 查看
1425: Careless Tony
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 92 Solved: 29
[Submit][Status][Web
Board]
Description
Tony is such a careless typist that he finds himself making mistakes AGAIN. What's worse, the cursor key is not working so that he can only use the backspace key to reach the place where the mistake is, and then type whatever he's deleted onthe way AGAIN :(
Now let's help Tony find out at least how long it will cost him to correct his mistake.
Input
The first line of input contains an integer N, which is the number of test cases. Then N test cases follow.Each test case consists of 3 lines of input:
the 1st line contains a positive integer t (<= 100), which is the time taken for Tony to delete/input a character;
the 2nd line contains the correct content of text;
and the 3rd line contains the text typed by Tony.
Note: The text contents contain only the readable characters. The total length of each text is no longer than 80 characters.
Output
For each test case, print in one line the minimal time taken for Tony to correct his mistake.Sample Input
21
WishingBone
WashingBone
1
Oops
Oooops
Sample Output
206
【解析】
这道题确实纠结了好久因为实在是看不懂啊..最后终于懂了。第一行输入的是有几组数据,第二行输入的是操作一个字符需要的时间,第三行输入的是正确的字符串,第四行是你输入的字符串。然后就行比对,看两者之间有哪些是不一样的。找到第一个不相同的字符,然后我们从第二个字符串的最后开始就行删除。删到第一个不一样的位置为止,如果两者之间长度相同并且字符都一样的话我们就输出0.如果第二个字符串的长度大于第一个字符串的长度,并且和第一个字符串长度相同的部分都是相同的那我们只需要删除后半部分就可以了,否则的话删除到第一个位置不一样的地方然后再变回和第一个字符串一样长度的字符串。
#include <iostream> #include <string> using namespace std; int main() { int n,t; string s1,s2; int flag; int p; cin>>n; while(n--) { cin>>t; cin>>s1>>s2; flag=1; p=0; for(int i=0;i<s1.size()&&i<s2.size();i++) { if(s1[i]!=s2[i])//寻找第一个不相同的字符串 { flag=0;//判断字符是否相同 p=i; break; } } if(flag)//字符都相同的话 { if(s1.size()>=s2.size()) { cout<<t*(s1.size()-s2.size())<<endl;//第一个字符串的长度减去第二个字符串的长度表示还有多少个字符 } else { cout<<(s2.size()-s1.size())*t<<endl;//还需要删除多少个字符 } } else { cout<<(s1.size()+s2.size()-2*p)*t<<endl;//表示的是我们先删除,然后再变成和第一个字符串一样的字符串 } } return 0; }
相关文章推荐
- ZCMU—1425
- sort 1425 hdu(hash 和 sort排序)
- ZOJ1425 POJ1692 Crossed Matchings
- hdu 1425
- hdu_1425_sort ( hash 入门 )
- HDU 1425 sort
- HDU 1425 sort hash+加速输入
- hdu acm 1425 sort(哈希表思想)
- hdu 1425 hash入门
- HDU 1425 sort 【哈希入门】
- HDOJ--1425 SORT (刚开始学ACM,用的是最简单的方法)
- hdu1425 sort (朴素)
- HDU 1425 sort
- HDU 1425 sort 题解
- zcmu 1615: 找区间
- ZCMU—1273
- ZCMU—1668
- ZCMU—1130
- ZCMU—1777
- ZCMU—1610