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

郁闷!为什么就是WA呢?(附程序)

Posted by hujk2008 at 2004-07-05 00:17:24 on Problem 1002
#include<stdio.h>
#include<stdlib.h>
int a[100002]={0};
int change[26] = {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,9};
int cmp(const void * x,const void * y)
{
	int * p, * q;
	p=(int *)x;
	q=(int *)y;
	if(*p>*q) return 1;
	if(*p==*q) return 0;
	if(*p<*q) return -1;

}
int main()
{
	int n,i,j=0,mark,count,hujk=0,hehe=0;
	char temp; 
	scanf("%d",&n);
	getchar();
	for (i=0;i<n;i++)
	{
		temp=getchar();
                if(temp==EOF)return 1;
		while(temp!='\n')
		{
			if(temp<='Z'&&temp>='A')
			{
				a[i]=a[i]*10+change[temp-'A'];
			}
                       else
			if(temp>='0'&&temp<='9')
			{
				a[i]=a[i]*10+temp-'0';
			}
			temp=getchar();
		}
	}

	j=0;
	qsort((void *)a,n,sizeof(int),cmp);
	while(j<n)
	{

                if(a[j]==0){j++;continue;}
		mark=a[j];
		count=1;
		while(j<n&&a[++j]==mark) count++;	
		if(count>1)
		{
	    	    printf("%3d-%4d %d\n",mark/10000,mark%10000,count);
	    	    hehe=1;
		}
	}
	if(!hehe)
		printf("No duplicates.\n");
	return 1;
}

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