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

互相学习一下,难道动态的分配空间不行的,老是RE(附code)测试都对的

Posted by RUNSLOWLY at 2008-11-09 01:13:22 on Problem 1002
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
using namespace std;
char *str[10000005];

int char_interpret(char c)
{
	if(c>='A'&&c<='C')
		return '2';
	if(c>='D' && c<='F')
		return '3';
	if(c>='G'&&c<='I')
		return '4';
	if(c>='J' && c<='L')
		return '5';
	if(c>='M' && c<='O')
		return '6';
	if(c=='P'||c=='R'||c=='S')
		return '7';
	if(c=='T'||c=='U'||c=='V')
		return '8';
	if(c=='W'||c=='X'||c=='Y')
		return '9';
	return c;
}

int cmp(const void *b,const void *a)
{
	return (strcmp(*(char **)b,*(char **)a));
}

void interpret(char *p)
{
	int i,k;
	k=0;
	for(i=0;*(p+i)!='\0';i++)
	{
		if(*(p+i)!='-')
		{
			*(p+k++)=char_interpret(*(p+i));
		}

	}
	*(p+k)='\0';
//	printf("%s\n",p);
}
int main()
{
	int i,n,sum,flag;
	flag=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		str[i]=(char *)malloc(sizeof(char *));
		cin>>str[i];
		interpret(str[i]);
	}
	qsort(str,n,sizeof(str[0]),cmp);
    	sum=1;
		for(i=1;i<n;i++)
		{
			if(strcmp(str[i-1],str[i])==0)
				sum++;
			else
			{
				if(sum>1)
				{
					flag=1;
					for(int j=0;str[i-1][j]!='\0';j++)
					{
						if(j==3)
							cout<<'-';
					   	cout<<str[i-1][j];							
					}
					cout<<' '<<sum<<endl;
				}
				sum=1;
			}
		}
	if(sum>1)
	{
		flag=1;
		for(int j=0;str[i-1][j]!='\0';j++)
		{
			if(j==3)
				cout<<'-';
			cout<<str[i-1][j];				
		}
		cout<<' '<<sum<<endl;
	}
	if(flag==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