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

水过,注意数组开大和没重复输出No duplicates.

Posted by Kindevil at 2012-04-17 01:33:58 on Problem 1002
#include<iostream>
#include<string.h>
using namespace std;

int Comp(const void* p1,const void* p2)
{
	return strcmp((char*)p1,(char*)p2);
}


int main()
{
	int Case,N,n=0,i;
	char s1[100],s2[100010][100];
	cin>>Case;
	N=Case;
	while(Case--)
	{
		int j=0;
		cin>>s1;
		int digit=strlen(s1);
		for(i=0;i<digit;i++)
		{
			if(j==3) 
			s2[n][j++]='-';
			switch(s1[i])
			{
			case 'A':case 'B':case 'C':s2[n][j++]='2';break;
			case 'D':case 'E':case 'F':s2[n][j++]='3';break;
			case 'G':case 'H':case 'I':s2[n][j++]='4';break;
			case 'J':case 'K':case 'L':s2[n][j++]='5';break;
			case 'M':case 'N':case 'O':s2[n][j++]='6';break;
			case 'P':case 'R':case 'S':s2[n][j++]='7';break;
			case 'T':case 'U':case 'V':s2[n][j++]='8';break;
			case 'W':case 'X':case 'Y':s2[n][j++]='9';break;
			case '-':break;
			default:s2[n][j++]=s1[i];
			}
		}
		s2[n][j]='\0';
		n++;
	}
	qsort(s2,N,sizeof(s2[0]),Comp);
	int t=0;
	for(i=0;i<N;i++)
	{
		int number=1;
		while(!strcmp(s2[i],s2[i+1])&&(i+1<N))
		{
			i++;
			number++;
		}
		if(number>1)
		{
			t++;
			cout<<s2[i]<<" "<<number<<endl;
		}
	}
	if(!t)
		cout<<"No duplicates."<<endl;
}


最开始没有注意No duplicates. 结果WA了。 然后数组开的30,WA了,后来数组开到100终于过了。

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