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 925695531 at 2010-12-02 23:41:41 on Problem 1002
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

char map[]="22233344455566677778889999";
char str[80],telnum[100000][9];

int main()
{
	void change(int);
	int compare(const void*elem1,const void*elem2);
	int n,i,j;
	bool a;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>str;
		change(i);
	}
	qsort(telnum,n,9,compare);
	a=true;
	for(i=0;i<n;i++)
	{
		j=i;
		i++;
		
		while(i<n&&strcmp(telnum[i],telnum[j])==0) i++;
		if(i-j>1)
		{
			cout<<telnum[j]<<" "<<i-j<<endl;
			a=false;
		}
	}
	if(a) cout<<"No duplicates."<<endl;
	return 0;
}

void change(int n)
{
	int j,k;
	j=-1;
	k=-1;
	while(k<8)
	{
		j++;
		if(str[j]=='-') continue;
		k++;
		if(k==3){
			telnum[n][k]='-';
			k++;
		}
		if(str[k]>='A'&&str[k]<='Z')
		{
			telnum[n][k]=map[str[j]-'A'];
		}
		else telnum[n][k]=str[j];
	}
	telnum[n][k]='\0';
}
int compare(const void*elem1,const void*elem2)
{
	return(strcmp((char*)elem1,(char*)elem2));
}

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