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

STL无压力,但是感觉好慢……

Posted by xyf at 2012-04-24 08:43:33 on Problem 1002
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <iostream>
using namespace std;

void init(); //Initialization
char cal(char k);// char -> num
void doit();// the main 

int n;
char s1[100];
string s2;
map<string,int> m;

int main()
{
		init();
		doit();
}

char cal(char k)
{
		switch (k)
		{
				case 'A' : case 'B':  case 'C': return '2';
				case 'D' : case 'E':  case 'F': return '3';
				case 'G' : case 'H':  case 'I': return '4';
				case 'J' : case 'K':  case 'L': return '5';
				case 'M' : case 'N':  case 'O': return '6';
				case 'P' : case 'R':  case 'S': return '7';
				case 'T' : case 'U':  case 'V': return '8';
				case 'W' : case 'X':  case 'Y': return '9';
		}
		return '#';
}

void init()
{
		scanf("%d",&n);
		for (int i = 1; i <= n; ++ i)
		{
				scanf("%s",s1);
				s2 = s1;
				string :: iterator it = s2.begin();
				int p = 0;
				while (p < s2.length())
				{
						if (s2[p] == '-') 
						{ 
							s2.erase(it+p); 
							continue; 
						}
						if ('A' <= s2[p] && s2[p] <= 'Z') s2[p] = cal(s2[p]);
						++ p;
				}
				s2.insert(it+3,'-');
				m[s2] = m[s2] + 1;
		}
}


void doit()
{
		bool ok = false;
		map<string,int>:: iterator it = m.begin();
		for (it = m.begin(); it != m.end(); ++ it)
			if ( (*it).second != 1) 
			{
				printf("%s %d\n",(*it).first.c_str(), (*it).second);
				ok = true;
			}
		if (! ok) printf("No duplicates.\n");
}

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