Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
自己测试的数据都正确,可一直wa,求解啊!!#include <iostream> using namespace std; int main() { int count; int loc; int cmp; const int maxn = 10000; char x[maxn], y[maxn]; while (cin >> x >> y) { loc = 0;//相等的位置location count = 0;//计数 int xlen = strlen(x);//求字符长度 int ylen = strlen(y); //从y字符串开始搜索 for (int i = 0; i < ylen; i++) { for (int j = loc; j < xlen; j++) { if (x[j] == y[i]) { loc = j + 1; count++; break; } } } cmp = count;//数据初始化 count = 0; loc = 0; //从x字符串开始搜索 for (int i = 0; i < xlen; i++) { for (int j = loc; j < ylen; j++) { if (x[i] == y[j]) { loc = j + 1; count++; break; } } } if (count>=cmp)//输出较大的 cout << count << endl; else cout << cmp << endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator