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

1171:为什用网络上的IOI 95 上的数据来测试都过了,在这里却wa了?错在哪里呢?

Posted by 2004huangyimin at 2008-08-05 17:08:16 on Problem 1171
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <string>
using namespace std;
int keyboard[30];
int main()
{
	keyboard[0] = 2;
	keyboard[1] = 5;
	keyboard[2] = 4;
	keyboard[3] = 4;
	keyboard[4] = 1;
	keyboard[5] = 6;
	keyboard[6] = 5;
	keyboard[7] = 5;
	keyboard[8] = 1;
	keyboard[9] = 7;
	keyboard[10] = 6;
	keyboard[11] = 3;
	keyboard[12] = 5;
	keyboard[13] = 2;
	keyboard[14] = 3;
	keyboard[15] = 5;
	keyboard[16] = 7;
	keyboard[17] = 2;
	keyboard[18] = 1;
	keyboard[19] = 2;
	keyboard[20] = 4;
	keyboard[21] = 6;
	keyboard[22] = 6;
	keyboard[23] = 7;
	keyboard[24] = 5;
	keyboard[25] = 7;

	char collected[9];
	int num[30];
	int copy[30];
	vector<string> vecTmp;
	int i;
	for(i = 0;i < 30;i++)
	{
		num[i] = 0;
	}
	scanf("%s",collected);
	int slen = strlen(collected);
	for(i = 0;i < slen;i++)
	{
		num[collected[i] - 'a'] += 1;
		copy[collected[i] - 'a'] = num[collected[i] - 'a'];
	}

	int max(0);
	char str[10];
	
//	char result[10];
//	char rsl[10];
	int tmp[30];
	while(scanf("%s",str))
	{
		int bIsChs = false;
		int sum(0);
		if(strcmp(str,".") == 0){break;}
		int len = strlen(str);
		for(i = 0;i < len;i++)
		{
			if(copy[str[i] - 'a']-- > 0){sum += keyboard[str[i]-'a'];}
			else{sum = 0;break;}
		}
		if(i >= len){bIsChs = true;}
///////////////////////////////////////////////////////////////////////////////////////
		vector<string>::iterator iter;
		int t_s = 0;
		int m = 0;
		string t_str;
		for(iter = vecTmp.begin();iter != vecTmp.end();iter++)
		{
			t_s = 0;
			for(i = 0;i < 30;i++)
			{
				tmp[i] = copy[i];
			}
			string t = (*iter);
			len = t.length();
			for(i = 0;i < len;i++)
			{
				if(tmp[t[i] - 'a']-- > 0){t_s += keyboard[t[i] - 'a'];}
				else{t_s = 0;break;}
			}
			if(t_s > m){m = t_s;t_str = t;}
		}
		sum += m;
//////////////////////////////////////////////////////////////////////////////////////
		if(bIsChs){vecTmp.push_back(str);}
		if(sum > max){max = sum;/*strcpy(result,str);strcpy(rsl,t_str.c_str());*/}
		for(i = 0;i < slen;i++)
		{
			copy[collected[i] - 'a'] = num[collected[i] - 'a'];
		}
	}
	printf("%d\n",max);
//	printf("%s\n",result);
//	printf("%s\n",rsl);
	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