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

用STL水过

Posted by acmxiaowuge at 2011-08-09 19:21:15 on Problem 1002
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string a,string b){
	return a<b;
}
int main(){
	int n,i;
	cin>>n;
	vector<string> vec;
	while(n--){
		string str,temp;
		cin>>str;
		for(i=0;i<str.size();i++){
			if(str[i]>='A'&&str[i]<='Z'){
				if(str[i]=='S'||str[i]=='V'||str[i]=='Y')
					temp.push_back((str[i]-'A')/3+1+'0');
				else
					temp.push_back((str[i]-'A')/3+2+'0');
			}
			else if(str[i]>='0'&&str[i]<='9'){
				temp.push_back(str[i]);
			}
		}
		temp.insert(3,"-");
		vec.push_back(temp);
	}
	sort(vec.begin(),vec.end(),cmp);
	bool flag=false;
	int times=0;
	for(i=0;i<vec.size();i++){
		if(i==0){
			times++;
			continue;
		}
		if(vec[i]==vec[i-1]){
			times++;
			if(i==vec.size()-1){
				if(times>1){
					flag=true;
					cout<<vec[i]<<" "<<times<<endl;
				}
			}
		}
		else{
			if(times>1){
				cout<<vec[i-1]<<" "<<times<<endl;
				flag=true;
			}
			times=1;
		}
	}
	if(flag==false)
		cout<<"No duplicates."<<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