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 evernever at 2006-03-17 21:03:15 on Problem 1002
#include<iostream.h>
#include <stdlib.h>
int n,i,j,k,l=0;
	char a[100001][20];
	int num[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9};
	int count[1000];
	long tele[100001];
int compare(const void *a,const void *b){
		return (*(int *)a-*(int *)b);
	}
void main(){
	cin>>n;
	for(i=0;i<n;i++){
		tele[i]=0;
		k=0;
		cin>>a[i];
		for(j=0;a[i][j]!='\0';j++){
			if(a[i][j]>='A' && a[i][j]<='Y'){
				tele[i]=tele[i]+num[a[i][j]-'A'];
				tele[i]=tele[i]*10;
			}
			else if(a[i][j]>='0' && a[i][j]<='9'){
				tele[i]=tele[i]+a[i][j]-'0';
				tele[i]=tele[i]*10;
			}
		}
		tele[i]=tele[i]/10;
	}
	qsort((void *)tele,n,sizeof(int),compare);
	for(i=0;i<n;i++){
		count[i]=1;
		for(k=0;k<i;k++){
			if(tele[k]==tele[i]){
				tele[i]=0;
				count[k]++;
			}
		}
	}

	for(i=0;i<n;i++){
		if(count[i]>1 && tele[i]!=0){
			l=1;
			cout<<tele[i]/10000<<"-"<<tele[i]%10000;
			cout<<" "<<count[i]<<endl;
		}
	}
	if(l!=1) cout<<"No duplicates."<<endl;
}

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