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 tcxgsy at 2005-10-05 20:37:31 on Problem 2629
#include "string.h"
#include "stdio.h"


int main(int argc, char* argv[])
{
	char a[1000],b[1000],c[1000];
	int lena,lenb,lenc,i,j,k;
	char temp;
	while(gets(a))
	{

		gets(b);
		lena=strlen(a);
		lenb=strlen(b);
		lenc=0;
		for(i=0;i<lena;i++)   //找出相同的
		{
			j=0;
			for(;j<lenb;j++)
			{
				if(a[i]==b[j]) 
				{
					if(lenc==0) {
						c[0]=a[i];
						lenc++;
						j=lenc;
					}
					else
					{
						int flag=0;
						for(k=0;k<lenc;k++)
						{
							if(a[i]==c[k])
								flag=1;
						}
						if(flag==0)
						{
							c[lenc]=a[i];
							lenc++;
							j=lenc;
						}
					}
				}
			}
		}
		for(i=0;i<lenc;i++)            //按照字母顺序排序
		{
			for(j=0;j<=lenc;j++)
				if(c[i]<c[j]) 
				{
					temp=c[i];
					c[i]=c[j];
					c[j]=temp;
				}
		}
		for(i=0;i<lenc;i++)
		{printf("%c",c[i]);
		c[i]=0;}

		printf("\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