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

Re:我的解答250MS

Posted by lhdtigerblue at 2010-08-01 14:20:36 on Problem 1002
In Reply To:我的解答250MS Posted by:yubo555123 at 2010-07-26 22:31:10
> #include <stdio.h>
> #include <algorithm>
> using namespace std;
> int main()
> {
> 	int n;
> 	char s[80];
> 	int a[100000];
> 	int i,k;
> 	int c = 0;
> 	int f,g=1;
> 
> 	scanf("%d", &n);
> 	getchar();
> 	for(k=0; k<n; ++k)
> 	{
> 		int u = 0;
> 		int f = 0;
> 
> 		gets(s);
> 		for (i=0; s[i]!='\0'; ++i)
> 		{
> 			switch (s[i])
把这个switch改为直接映射,会更快。
static char maps[] = 
"                                                                 "
"2223334445556667777888999";
a[k] = maps[s[i]];
> 			{
> 			case 'A':
> 			case 'B':
> 			case 'C':
> 				u = u*10+2;
> 				break;
> 			case 'D':
> 			case 'E':
> 			case 'F':
> 				u = u*10+3;
> 				break;
> 			case 'G':
> 			case 'H':
> 			case 'I':
> 				u = u*10+4;
> 				break;
> 			case 'J':
> 			case 'K':
> 			case 'L':
> 				u = u*10+5;
> 				break;
> 			case 'M':
> 			case 'N':
> 			case 'O':
> 				u = u*10+6;
> 				break;
> 			case 'P':
> 			case 'R':
> 			case 'S':
> 				u = u*10+7;
> 				break;
> 			case 'T':
> 			case 'U':
> 			case 'V':
> 				u = u*10+8;
> 				break;
> 			case 'W':
> 			case 'X':
> 			case 'Y':
> 				u = u*10+9;
> 				break;
> 			default:
> 				if (s[i]>='0' && s[i]<='9')
> 					u = u*10+s[i]-48;
> 			}
> 		}
> 
> 		a[k] = u;
> 	}
> 
> 	sort(a, a+n);
> 	f = a[0];
> 	for (i=1; i<n; ++i)
> 	{
> 		if (a[i] == f)
> 			++g;
> 		else 
> 		{
> 			if (g != 1)
> 			{
> 				printf("%03d-%04d %d", f/10000, f%10000, g);
> 				printf("\n");
> 				c = 1;
> 			}
> 			f = a[i];
> 			g = 1;
> 		}
> 	}
> 
> 	if (g != 1)
> 	{
> 		printf("%03d-%04d %d", f/10000, f%10000, g);
> 		c = 1;
> 	}
> 
> 	if (!c)
> 		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