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

贴个我自己的例子

Posted by mlion at 2009-09-18 20:00:56 on Problem 1002 and last updated at 2009-09-18 20:01:13
AC了 用map 和cout 新手 没什么效率 代码也不好 不要见笑
#include "iostream"
#include "map"
#include "string"
#include "cctype"
using namespace std;
int main(int argc, char* argv[])
{
	int number;
	string  input;
	string::iterator iter;
    map <string ,int> phonenum;
	cin>>number;
	while(number)
	{
      cin>>input;
	  iter=input.begin();
      while(iter!=input.end())
	  {
      if(isalpha(*iter))
	  {
		  if((*iter)=='A'||(*iter)=='B'||(*iter)=='C')
			  *iter='2';
		  else if((*iter)=='D'||(*iter)=='E'||(*iter)=='F')
			  *iter='3';
		  else if((*iter)=='G'||(*iter)=='H'||(*iter)=='I')
			  *iter='4';
		  else if((*iter)=='J'||(*iter)=='K'||(*iter)=='L')
			  *iter='5';
		  else if((*iter)=='M'||(*iter)=='N'||(*iter)=='O')
			  *iter='6';
		  else if((*iter)=='P'||(*iter)=='R'||(*iter)=='S')
			  *iter='7';
		  else if((*iter)=='T'||(*iter)=='U'||(*iter)=='V')
			  *iter='8';
		  else if((*iter)=='W'||(*iter)=='X'||(*iter)=='Y')
			  *iter='9';
		  iter++;
	  }
	  else if(isdigit(*iter))
		           iter++; 
	  else
		 iter=input.erase(iter);
	  }
	 input.insert(input.begin()+3,'-');
	++phonenum[input];
	 number--; 
	}
	map<string, int>::iterator map_it;
        bool flag=0;
	for(map_it=phonenum.begin();map_it!=phonenum.end();map_it++)
	{
		if(map_it->second>1)
		{
                flag=1;
		string::iterator iter1;	
		cout<<map_it->first<<' '<<map_it->second<<endl;
		}
               
	}
        if(flag==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