View Code of Problem 22

#include <stdio.h>

int main()
{
	int i,j;
	char a[1000];
	char b[1000];
	
	
	while(gets(a) != NULL)
	{
		char c[1000];
		gets(b);
		int k=0;
		for(i=0;i<strlen(a);i++)//找出相同的字母 
		{
			for(j=0;j<strlen(b);j++)
			{
				if(a[i]==b[j])
				{
					c[k++]=a[i];
					 
					b[j]='#';//防止有相同的字母多次输出 
					break;
				}
			}
		}
		//c[k]='\0';
		for(i=0;i<k;i++)//字母排序 
		{
			char temp;
			for(j=i+1;j<k;j++)
			{
				if(c[i]>c[j])
				{
					temp=c[j];
					c[j]=c[i];
					c[i]=temp;
				}
			}
		}
		for(i=0;i<k;i++)
		{
			printf("%c",c[i]);
			
		}
		printf("\n");
		
	}
	
	
	return 0;
} 

Double click to view unformatted code.


Back to problem 22