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 hdm29682 at 2006-02-13 23:46:11 on Problem 1002
#include <iostream>
#include <algorithm>
using namespace std;
const char table[]={"22233344455566677778889999"};
struct sm{char i[9];int c;sm(){c=0;}};
void GetI(char* s,char* o)
{
	int r=0;
	while(*s!='\0'){
		if(r==3)o[r++]='-';
		{
			if(*s>='A'&&*s<='Z'){
				o[r++]=table[*s-'A'];
			}
			else if(*s>='0'&&*s<='9'){
				o[r++]=*s;
			}
		}
		++s;
	}
}
bool cmp(sm a,sm b){return strcmp(a.i ,b.i)<0;}
int main()
{
	int n,cur=0;bool val=true;
	cin>>n;
	sm num[100000];//=new sm[n];
int z;	for(z=0;z<n;z+=1)
	{
		char str[64],aa[9];aa[8]=0;
		cin>>str;
		GetI(str,aa);
		int i;for(i=0;i<cur;i++)
		{
			if(strcmp(num[i].i,aa)==0)
			{
				num[i].c++;
				break;
			}
		}
		if(i==cur)
		{
			strcpy(num[i].i,aa);num[i].c=1;
			cur++;
		}
	}
	sort(num,num+cur,cmp);
	for(z=0;z<cur;z++)
	{
		if(num[z].c >1)
		{
			val=false;
			cout<<num[z].i<<" "<<num[z].c<<endl;
		}
	}
	if(val)cout<<"No duplicates."<<endl;
}

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