View Code of Problem 22

#include "stdio.h"
#include "string.h"

void main()
{
	char a[1000],b[1000],c[1000];
	int i,j,k;
	char temp;
	for(;scanf("%s\n%s",a,b)!=NULL;)
	{
		for(k=0,i=0;a[i]!='\0';i++)
		{
			for(j=0;b[j]!='\0';j++)
			{
				if(a[i]==b[j])
				{
					c[k]=a[i];
					k++;
				}

			}
		}
		c[k]='\0';
		for(i=0;i<strlen(c);i++)
		{
			for(j=0;j<strlen(c)-i-1;j++)
			{
				if(c[j]>c[j+1])
				{
					temp=c[j];c[j]=c[j+1];c[j+1]=temp;
				}
			}
		}
		for(i=0;c[j]!='\0';i++)				//去重
		{
			if(c[i]==c[i+1])
			{
				for(j=i;c[j]!='\0';j++)
				{
					c[j]=c[j+1];
				}
			}
		}
		puts(c);
	}
}

Double click to view unformatted code.


Back to problem 22