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 nasta at 2011-05-25 22:00:58 on Problem 1002
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct Tel
{
	string num;
	int count;

	bool operator < (const Tel &t)
	{
		if(num < t.num)
			return true;
		return false;
	}
};

string trans(const string &s)
{
	string o;
	int j = 0;
	for(int i = 0; i != s.size(); i++)
	{
		if(j == 3)
		{
			o += '-';
			j++;
		}
		if(isdigit(s[i]))
		{
			o += s[i];
			j++;
		}
		else
		{
			switch(s[i])
			{
			case 'A':case 'B':case 'C':
				o += '2';
				j++;
				break;
			case 'D':case 'E':case 'F':
				o += '3';
				j++;
				break;
			case 'G':case 'H':case 'I':
				o += '4';
				j++;
				break;
			case 'J':case 'K':case 'L':
				o += '5';
				j++;
				break;
			case 'M':case 'N':case 'O':
				o += '6';
				j++;
				break;
			case 'P':case 'R':case 'S':
				o += '7';
				j++;
				break;
			case 'T':case 'U':case 'V':
				o += '8';
				j++;
				break;
			case 'W':case 'X':case 'Y':
				o += '9';
				j++;
				break;
			}
		}
	}
	return o;
}

int main()
{
	int n;
	scanf("%d\n", &n);

	vector<Tel> book;

	for(int i = 0; i < n; i++)
	{
		char st[20];
		scanf("%s", st);

		string t(st);
		t = trans(t);
		bool state = true;
		for(int i = 0; i != book.size(); i++)
		{
			if(book[i].num == t)
			{
				state = false;
				book[i].count++;
				break;
			}
		}
		if(state)
		{
			Tel tmp;
			tmp.num = t;
			tmp.count = 1;
			book.push_back(tmp);
		}
	}
	sort(book.begin(), book.end());
	int num = 0;
	for(int i = 0; i < book.size(); i++)
	{
		if(book[i].count > 1)
			printf("%s %d\n", book[i].num.c_str(), book[i].count);
		num++;
	}
	if(num == 0)
		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