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

给出我的AC代码,仅供参考

Posted by seedeed at 2011-02-02 15:55:47 on Problem 1002
#include "cstdio"
#include "cstring"
#include "cstdlib"
int hash[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,1,7,7,8,8,8,9,9,9,1};
char ch[100],ans[9]="000-0000";
int arr[100000];
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
    int n,temp,i,j,num=1;
	bool flag=false;
    scanf("%d",&n);
    for(j=0;j<n;j++)
    {
        temp=0;
        scanf("%s",ch);
        for(i=0;ch[i];i++)
        {
            if(ch[i]>='A'&&ch[i]<='Z'&&ch[i]!='Q'&&ch[i]!='Z') temp=temp*10+hash[ch[i]-'A'];
            else if(ch[i]>='0'&&ch[i]<='9') temp=temp*10+ch[i]-'0';
        }
        arr[j]=temp;
    }
	qsort(arr,n,sizeof(int),cmp);
	for(i=0;i<n;i++)
	{
		if(i+1<n&&arr[i]==arr[i+1]) 
		{
			num++;
			flag=true;
		}
		else
		{
			strcpy(ans,"000-0000");
			for(j=7;j>=0&&arr[i];j--)
			{
				if(j!=3)
				{
					ans[j]=arr[i]%10+'0';
					arr[i]/=10;
				}
				else ans[j]='-';
			}
			if(num>1) printf("%s %d\n",ans,num);
			num=1;
		}
	}
	if(!flag) puts("No duplicates.");
    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