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

真不知道哪里错了,55555555555555555555555555555555555555555555555555555555555

Posted by fjctlzy at 2006-07-21 19:34:22 on Problem 1002
#include<iostream>
#include<algorithm>
using namespace std; 
int cmp ( const void * a ,const void * b ){
	return strcmp( (char*)a, (char*)b );
}

bool same( char a[100], char b[100]){
	for (int i=0;i<7;i++) if (a[i]!=b[i]) return false;
	return true;
}


int change(char ch){
	switch(ch){
	case 'A': case 'B': case 'C':
		return 2; 
		break;
	case 'D': case 'E': case 'F':
		return 3; 
		break;
	case 'G': case 'H': case 'I':
		return 4; 
		break;
	case 'J': case 'K': case 'L':
		return 5; 
		break;
	case 'M': case 'N': case 'O': 
		return 6; 
		break;
	case 'P': case 'R': case 'S':
		return 7; 
		break;
	case 'T': case 'U': case 'V': 
		return 8; 
		break;
	case 'W': case 'X': case 'Y': 
		return 9; 
		break;
	}
}

int main(){
	int len,i,j,k,n;
	char a[100];int num;
	char b[1000][100];
	cin>>n;
	num=0;
	for (i=0;i<n;i++){
		cin>>a;
		len=strlen(a);
		k=0;
		for (j=0;j<len;j++){
			if (isdigit(a[j])){
               b[i][k]=a[j];
			   k++;
			}
			else if (isalpha(a[j])){
				b[i][k]=change(a[j])+'0';
			    k++;
			}
		}
	}

	qsort(b,n,sizeof(b[0]),cmp);
	i=0;j=1;
	bool ok=false;
	while(i<n){
		num=1;
		while(same(b[i],b[j])){
			j++;
			num++;
		}
		if (num>1){
			ok=true;
			for (k=0;k<=2;k++) cout<<b[i][k];
		    cout<<'-';
		    for (k=3;k<=6;k++) cout<<b[i][k];
		    cout<<" "<<num<<endl;
		}
		i=j;
		j++;
	}
	if(!ok) 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