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

ole~~call for help T_T

Posted by Qteqpid at 2007-10-30 15:47:50 on Problem 2629
#include<iostream>
using namespace std;
int comp(const void *a, const void *b)
{ return *(char *)a - *(char *)b; }
void main()	
{
	char a[1010], b[1010];
	int alp[26];
	int lena, lenb, i;
	while(1)
	{	
		gets(a);		
		if( 0 == strlen(a) ) break;

		gets(b);
		qsort(b,strlen(b),sizeof(b[0]),comp);

		memset(alp,0,sizeof(alp));
		lena = strlen(a);
		lenb = strlen(b);

		for( i = 0; i < lena ; i++ )
		{
			if( a[i] >= 'a' && a[i] <= 'z' ) alp[a[i]-'a']++;
		}
		for( i = 0 ; i < lenb; i++ )
		{
			if( b[i] >= 'a' && b[i] <= 'z' && alp[b[i]-'a'] > 0 )
			{
				alp[b[i]-'a']--;
				cout<<b[i];
			}
		}
		cout<<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