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

蒟蒻的AC纪念

Posted by CrystalBall at 2016-10-05 12:49:10 on Problem 1002
最初忽略了开头为0的情况。
挺慢,该怎么优化······
膜拜那些快速通过的大神!


#include <cstdio>
#include <map>
#include <ctype.h>
using namespace std;

#define elif else if

int Deal(int c)
{
	if (isdigit(c))
		return c;
	elif (c>='A' && c <= 'C')
		return '2';
	elif (c>='D' && c <= 'F')
		return '3';
	elif (c>='G' && c <= 'I')
		return '4';
	elif (c>='J' && c <= 'L')
		return '5';
	elif (c>='M' && c <= 'O')
		return '6';
	elif (c>='P' && c <= 'S')
		return '7';
	elif (c>='T' && c <= 'V')
		return '8';
	elif (c>='W' && c <= 'Y')
		return '9';
	else 
		return -1;
}
int Myscan()
{
	int val = 0;
	int c;
	while ((c = getchar()) != EOF && c != ' ' && c != '\n')
	{	
		if (c=='-')
			continue;
	  	else
	  		val = val*10 + Deal(c)-'0';
	}
	while (c ==' ')
		c = getchar();
	return val;
}
int main()
{
	int i;
	int n;
	bool mark = false;
	const int k= 10000;
	map<int, int>pbook;
	map<int, int>::iterator it;
	
	n = Myscan();
	for(i=1;i<=n;i++)
		pbook[Myscan()]++;
	for (it = pbook.begin(); it != pbook.end(); it++)
	{
		if(it->second > 1)
		{
			if(!mark)
				mark = true;
			printf("%03d-%04d %d\n",it->first/k,it->first%k,it->second);
		}
	}	
	if(!mark)
		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