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 LZSY1 at 2018-08-27 20:20:25 on Problem 1002
In Reply To:上代码 Posted by:lzxzy at 2018-08-27 11:52:45
#include <cstdio>
#include <cstring>
#include <algorithm>//使用sort排序要调用
using namespace std;
int n,sum;
int a[100005];
char ch[15];
bool flag=0;

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

void into()
{
	int len;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",ch);
		len=strlen(ch);
		sum=0;
		for(int j=0;j<len;j++)
		{
			if(ch[j]=='-')continue;
			if(ch[j]=='Q' || ch[j]=='Z')continue;
			if(ch[j]>='0' && ch[j]<='9')sum=sum*10+ch[j]-48;
			if(ch[j]>='A' && ch[j]<='Z')sum=sum*10+pd(ch[j]);
		}
		if(sum>=10000000)continue;
		a[i]=sum;
	}
}

int main()
{
	into();
	sort(a+1,a+n+1);//STL模板
	for(int i=1,sum=1;i<=n;i++,sum=1)
	{
    	        while(a[i]==a[i+1])
    	        {	
			sum++;i++;
		}
		if(sum>1)
		{
    		        printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,sum);
		        flag=1;
                }
        }
	if(!flag)printf("No duplicates. \n");
	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