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

多谢大神,附代码

Posted by bryant03 at 2014-07-28 11:30:23 on Problem 1580
In Reply To:Re:试试这个测试数据 "AAAB" ," BAAA",或许会有帮助 Posted by:black_snow at 2009-07-21 09:40:01
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	else return gcd(b, a%b);
}
int main()
{
	char str1[500], str2[500];
	int i, j, len1, len2, count, temp;
	while (cin >> str1)
	{
		if (strcmp(str1,"-1")==0)
			break;
		cin >> str2;
		temp = 0;
		len1 = strlen(str1);
		len2 = strlen(str2);
		for (i = 0; i<len1; i++){
			count = 0;
			for (j = 0; i + j<len1&&j<len2; j++)
				if (str2[j] == str1[i + j])
					count++;
			if (count > temp)
				temp = count;
		}
		for (i = 0; i<len2; i++){
			count = 0;
			for (j = 0; i + j<len2&&j<len1; j++)
				if (str1[j] == str2[i + j])
					count++;
			if (count > temp)
				temp = count;
		}
		if (temp == 0){
			cout << "appx(" << str1 << ',' << str2 << ") = " << temp << endl;
			continue;
		}
		if (2 * temp == (len1 + len2)){
			cout << "appx(" << str1 << ',' << str2 << ") = " << 1 << endl;
			continue;
		}
		cout << "appx(" << str1 << ',' << str2 << ") = " << 2 * temp / gcd(2 * temp, len1 + len2) << '/' << (len1 + len2) / gcd(2 * temp, len1 + len2) << 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