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 earnAlive at 2014-04-02 15:27:31 on Problem 1002
最开始,还想到用二维数组存储,竟然不知道转化为整型变量,感觉自己真是弱爆了。。。
<code>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAXLEN 100000
using namespace std;


int phone[MAXLEN];
int counter[MAXLEN];

int convert(char str[])
{
	int num=0;
	int i=0;
	while(str[i]!='\0')
	{
		switch(str[i])
		{
			case '0':num=num*10;break;
			case '1':num=num*10+str[i]-'0';break;
			case '2':case 'A':case 'B':case 'C':num=num*10+2;break;
			case '3':case 'D':case 'E':case 'F':num=num*10+3;break;
			case '4':case 'G':case 'H':case 'I':num=num*10+4;break;
			case '5':case 'J':case 'K':case 'L':num=num*10+5;break;
			case '6':case 'M':case 'N':case 'O':num=num*10+6;break;
			case '7':case 'P':case 'R':case 'S':num=num*10+7;break;
			case '8':case 'T':case 'U':case 'V':num=num*10+8;break;
			case '9':case 'W':case 'X':case 'Y':num=num*10+9;break;
		}
		i++;
	}
	return num;
}

int main() 
{
	int n,i,j,num;
	int pre,sub;
	int flag=0;
	
	char str[300];
	memset(phone,0,sizeof(phone));
	memset(counter,0,sizeof(counter));
	counter[0]=1;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",str);
		num=convert(str);
		phone[i]=num;
	}
	sort(phone,phone+n);
	for(i=1,j=0;i<n;i++)
	{
		if(phone[i]==phone[j])
		{
			counter[j]++;
		}else
		{
			phone[++j]=phone[i];
			counter[j]++;
		}
	}
	for(i=0;i<=j;i++)
	{
		if(counter[i]>1)
		{
			flag=1;
			pre=phone[i]/10000;
			sub=phone[i]%10000;
			printf("%03d-%04d %d\n",pre,sub,counter[i]);
		}
	}
	if(!flag)
	printf("No duplicates.\n");
	return 0;
}
</code>

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