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 zerocpp at 2011-01-13 16:39:42 on Problem 1002
1. 每行输入的字符串长度可能很长,char str[20]就WA了,char str[100]就AC了。
2. 将每个电话号码转成数字(num<10^7),然后++ map[num]
3. 输入量很大,建议采用scanf或gets
4. 输出可以采用这种方式:printf("%03d-%04d %d\n", it->first/10000, it->first%10000, it->second);

G++ 600+ms

#include <iostream>
#include <string>
#include <map>
#include <iterator>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
inline int c(const char & ch)
{
	switch (ch)
	{
		case '0': return 0;
		case '1': return 1;
		case 'A': case 'B': case 'C': case '2': return 2;
		case 'D': case 'E': case 'F': case '3': return 3;
		case 'G': case 'H': case 'I': case '4': return 4;
		case 'J': case 'K': case 'L': case '5': return 5;
		case 'M': case 'N': case 'O': case '6': return 6;
		case 'P': case 'R': case 'S': case '7': return 7;
		case 'T': case 'U': case 'V': case '8': return 8;
		case 'W': case 'X': case 'Y': case '9': return 9;
	}
	return -1;
}
map<int, int> mp;
int main()
{
	char str[100];
	int res, cas;
	scanf("%d", &cas);
	while (getchar() != '\n');
	while (cas --)
	{
		gets(str);
		res = 0;
		for (int i = 0; str[i]; ++ i)
		{
			if (str[i] != '-')
			{
				res = res * 10 + c(str[i]);
			}
		}
		++ mp[res];
	}
	bool b = 0;
	for (map<int, int>::const_iterator it = mp.begin(); it != mp.end(); ++ it)
	{
		if (it->second > 1)
		{
			b = 1;
			printf("%03d-%04d %d\n", it->first/10000, it->first%10000, it->second);
		}
	}
	if (!b)
	{
		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