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

老是wronganswer, 不明白啊! 谁能帮忙看下(code);

Posted by woshiniya at 2006-12-10 21:44:34 on Problem 1583
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

void main() {
	int len, i, j, max, p;
	char alp[81];
	string tmp;
	vector< string > ans;
	vector<int> index;
	while(scanf("%s", alp) != EOF) {
		len = strlen(alp);
		tmp = "";
		i = len - 1;
		p = 1;
		for(i = len-1; i >= 0; i--)
			if((alp[i]>='a'&& alp[i]<='z')||(alp[i]>='A'&&alp[i]<='Z')||(alp[i]>='0'&&alp[i]<='9'))
			         break;
		for(j = 0; j <= i; j++) {
			if(isupper(alp[j]))
				alp[j] = tolower(alp[j]);
			tmp += alp[j];
		}
		ans.insert(ans.end(), tmp);
		index.insert(index.end(), 0);
	}
	sort(ans.begin(), ans.end());
	max = 0;
	if(ans.size()) {
		index[0] = 1;
		max = 1;
	}
	for(i = 1; i < ans.size(); i++) {
		if(ans[i] == ans[i-1])
			index[i] = index[i-1] + 1;
		else 
			index[i] = 1;
		if(index[i] > max)
			max = index[i];
	}
	printf("%d occurrences\n", max);
	for(i = 0; i < ans.size(); i++) {
		if(index[i] == max)
			cout << ans[i] << endl;
	}
	
}

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