Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

晕 还是WA...莫非我理解错了?

Posted by yescrystal at 2006-12-16 00:55:20 on Problem 3158
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

string a, b;

int cal()
{
	int i, j, k;
	i = 0;
	while(i<b.length())
	{
		k = 0;
		while(k<a.length())
		{
			j = k+i;
			if(!(b[j] == '2' && a[k]=='2') ||j>=b.length())
				k++;
			else break;
		}
		if(k==a.length())
		{
			int ans = i+a.length();
			if(ans < b.length()) ans = b.length();
			return ans;
		}
		i++;
	}
	return a.length()+b.length();
}

int main()
{
	while(cin >> b >> a)
	{
		int x1 = cal();
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		int x2 = cal();
		if(x2>x1) x2 = x1;
		cout << x2 << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator