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

4013ms就差13ms了,我实在不知怎么改了,又不想重写,所以希望大家提点意见,谢谢

Posted by xieyixiewen2 at 2007-08-26 11:32:34 on Problem 1002
#include <iostream>
#include <string>
#include <map>
using namespace std;

void convert(string & raw) {
	for(int i=0;i<raw.length();i++) {
		if(i==3 && raw[i] != '-')
			raw.insert(3,"-");
		else if(raw[i] == '-') {
			//如果是‘-’就删除
			raw.erase(i,1);
			i--;
		} else if(isalpha(raw[i])) {
			//否则替换
			switch(raw[i]) {
				case 'A'...'C':
					raw[i]='2';break;
				case 'D'...'F':
					raw[i]='3';break;
				case 'G'...'I':
					raw[i]='4';break;
				case 'J'...'L':
					raw[i]='5';break;
				case 'M'...'O':
					raw[i]='6';break;
				case 'P'...'S':
					raw[i]='7';break;
				case 'T'...'V':
					raw[i]='8';break;
				case 'W'...'Y':
					raw[i]='9';break;
			}
		}
	}
}

int main() {
	int num;
	scanf("%d",&num);
	map<string,unsigned int> counter;
	string str;
	for(int i=0;i<num;i++) {
		cin>>str;
		convert(str);
		counter[str]++;
	}
	bool flag = false;
	for(map<string,unsigned int>::iterator it=counter.begin();it!=counter.end();it++) {
		if(it->second != 1) {
			cout<<it->first<<" "<<it->second<<endl;
			flag = true;
		}
	}
	if(!flag)
		printf("No duplicates. \n");
}

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