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

Re:

Posted by capgemini at 2010-07-20 12:33:10 on Problem 1002
In Reply To:给几个数据给大家。借鉴 Posted by:fbixiaozc135 at 2007-08-05 01:21:19
你们的测试数据我在我的代码上跑了下,都能顺利通过,但是提交不能过,请你们指教,谢谢~~~~
下面是我的代码。
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;

string format(string s){
	string temp = s;
	char c;
        //把字母转换成数字
	for(int i=0;i<s.length();i++){
		c=temp.at(i);
		
		switch(c){
			case 'A':
			case 'B':
			case 'C': 	temp.replace(i,1,1,'2'); 	break;
			
			case 'D':
			case 'E':
			case 'F':	temp.replace(i,1,1,'3'); 	break;
				
			case 'G':
			case 'H':
			case 'I':	temp.replace(i,1,1,'4'); 	break;
				
			case 'J':
			case 'K':
			case 'L':	temp.replace(i,1,1,'5'); 	break;
				
			case 'M':
			case 'N':
			case 'O':	temp.replace(i,1,1,'6');	break;
				
			case 'P':
			case 'R':
			case 'S':	temp.replace(i,1,1,'7');	break;
			
			case 'T':
			case 'U':
			case 'V':	temp.replace(i,1,1,'8');	break;
			
			case 'W':
			case 'X':
			case 'Y':	temp.replace(i,1,1,'9');	break;	
			}
		}
//去掉'-'
		while(temp.at(0)=='-') temp = temp.substr(1,temp.length()-1); 
		while(temp.at(temp.length()-1)=='-')  temp=temp.substr(0,temp.length()-1);	
			
		string::iterator   it=temp.begin();
		
    	for (it =temp.begin(); it != temp.end(); ++it){
        	while( *it == '-'){
            	temp.erase(it);
        	}
   		 }
		//if(temp.length()==7){temp.insert(3,"-");}
		//cout<<"after format:"<<temp<<endl;
		return temp;
}
//格式化,输出用
string addLine(string s){
	return s.insert(3,"-");
	//return s;
	}
	
int main(){
	int n;
	cin>>n;
	vector<string> origin;
	string in;
	string com;
	int total = 1;	
        //接受输入,并格式化后放到vector
	for(int i=0;i<n;i++){
		cin>>in;	
		origin.push_back(format(in));
	}
        //排序	
	sort(origin.begin(),origin.end());	
	//cout<<"after sort:"<<endl;
	//for(int i=0;i<n;i++){cout<<origin.at(i)<<endl;}
	//输出。
	com = origin.at(0);	
	for(int i=1;i<n;i++){
		if(com.compare(origin.at(i))==0){
			total = total + 1;
			if(i==(n-1))cout<<addLine(com)<<" "<<total<<endl;
		}else{
			if(total!=1){
				cout<<addLine(com)<<" "<<total<<endl;
				total = 1;
				}
				
		}
		com = origin.at(i);
	}
	system("pause");
}

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