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:贴个StL的代码。。。1.5s

Posted by mci2004 at 2013-06-14 00:24:40 on Problem 1002
In Reply To:贴个StL的代码。。。1.5s Posted by:ZxyElf at 2013-02-14 21:36:56
> #include <iostream>
> #include <map>
> #include <string>
> #include <algorithm>
> #include <vector>
> using namespace std;
> 
> bool cmp(const pair<string,int>& a,const pair<string,int>& b){
> 	for (int i=0;i<8;i++){
> 		if (a.first[i]==b.first[i]) continue;
> 		else return a.first[i]<b.first[i];
> 	}
> 	return true;
> }
> 
> int main()
> {
> 	int n,i,j,count;
> 	char marray[100];
> 	marray['1']='1';
> 	marray['0']='0';
> 	marray['A']=marray['B']=marray['C']=marray['2']='2';
> 	marray['D']=marray['E']=marray['F']=marray['3']='3';
> 	marray['G']=marray['H']=marray['I']=marray['4']='4';
> 	marray['J']=marray['K']=marray['L']=marray['5']='5';
> 	marray['M']=marray['N']=marray['O']=marray['6']='6';
> 	marray['P']=marray['R']=marray['S']=marray['7']='7';
> 	marray['T']=marray['U']=marray['V']=marray['8']='8';
> 	marray['W']=marray['X']=marray['Y']=marray['9']='9';
> 	cin>>n;
> 	char buf[1500];
> 	map<string,int> m;
> 	map<string,int>::iterator itr;
> 	for (i=0;i<n;i++){
> 		cin>>buf;
> 		count=0;
> 		string s;
> 		for (j=0;count<7;j++){
> 			if (buf[j]=='-') continue;
> 			s=s + marray[buf[j]];
> 			count++;
> 			if (count==3) s+='-';
> 		}
> 		if ((itr=m.find(s))==m.end())
> 			m.insert(make_pair(s,1));
> 		else
> 			(*itr).second++;
> 	}
> 	vector<	pair<string,int>> vec;
> 	for (itr=m.begin();itr!=m.end();itr++){
> 		if (itr->second>1)
> 		vec.insert(vec.end(),*itr);	
> 	}
> 	sort(vec.begin(),vec.end(),cmp);
> 	int total=vec.size();
> 	for (i=0;i<total;i++){
> 		cout<<vec[i].first<<' '<<vec[i].second<<endl;
> 	}
> 	if (vec.size()==0) 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