题目链接:http://cpp.zjut.edu.cn/ShowProblem.aspx?ShowID=1885
题面:
Careless Tony
Time Limit:1000MS Memory Limit:32768K
2 1 WishingBone WashingBone 1 Oops Oooops
20 6
题意:
最少用多少时间修改后面那个串到前面那个串。
代码:
#include <iostream> #include <string> using namespace std; int main() { int n,t; string s1,s2; bool flag; int p; cin>>n; while(n--) { cin>>t; cin>>s1>>s2; flag=true; p=0; for(int i=0;i<s1.length()&&i<s2.length();i++) { if(s1[i]!=s2[i]) { flag=false; p=i; break; } } if(flag) { if(s1.length()>=s2.length()) { cout<<t*(s1.length()-s2.length())<<endl; } else { cout<<(s2.length()-s1.length())*t<<endl; } } else { cout<<(s1.length()+s2.length()-2*p)*t<<endl; } } return 0; }
原文地址:http://blog.csdn.net/david_jett/article/details/45104103