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 cpp00548322 at 2006-03-12 15:20:10 on Problem 1002
#include<string.h>
#include<stdio.h>
#include<stdlib.h>

char result[100000][15];

int compare(const void * a,const void * b);

int main()
{
	char Letters[25]="ABCDEFGHIJKLMNOPRSTUWXY";
	char integers[25]="222333444555666777888999";
	int N;scanf("%d\n", &N);
	if(N==0) return 1;
	char teleNum[15];
	int i=0,value=1;
	for(i=0 ; i < N ; i++)
	{
		scanf("%s",teleNum);
		int len=strlen(teleNum),sign=0,k=0;
		char chr; 
		for(k=0;k<=len;k++)
		{
			chr=teleNum[k]; 
			if(chr=='Q'||chr=='Z') break;
			if(chr=='-') continue;
			
			else if(chr<='Z'&&chr>='A')
			{int j=0;
				for(j=0;j<24;j++)
				if(chr==Letters[j]) break;
				chr=integers[j];
			}
			sprintf(result[i],"%s%c",result[i],chr);
			sign++;
			if(sign==3) 
			sprintf(result[i],"%s%c",result[i],'-'); 
			
		}
	}
	//排序
	printf("%\n");
	qsort((void *)result, N, sizeof(result[0]),compare);
//	printf("%\n");
	for(int q=0;q<N;q++)printf("%s\n",result[q]);
	int repeat=1,j=0;
	for(i=0;i<N;)
	{
		repeat=1;
		if( strcmp(result[i],"ZQ")==0) continue;
		for(j=i+1;j<N && strcmp(result[i],result[j])==0;j++)
			repeat++;
		
	//	if(i==N-2 &&
		if(repeat!=1)
		{
			printf("%s %d\n",result[i],repeat);
			value=0;
		}
		i=j;
	}
	if(value)printf("No duplicates.\n");
	return 1;
}
			
int compare(const void * a,const void * b)
{
	return strcmp((char *)a,(char *)b);
}

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