View Code of Problem 22

#include<string.h>
#include<stdio.h>
int main(){
	char t,a[1000],b[1000],c[1000];
	int k,la,lb;
	while(gets(a)){
		gets(b);
		k=0;
		la=strlen(a);
		lb=strlen(b);
		for(int i=0;i<la;i++){
			for(int j=0;j<lb;j++){
				if(a[i]==b[j]){
					c[k++]=a[i];
					b[j]='*';
					break;
				}
			}
		}
		for(int i=0;i<k;i++){
			for(int j=i+1;j<k;j++){
				if(c[i]>c[j]){
					t=c[j];
					c[j]=c[i];
					c[i]=t;
				}
			}
		}
		c[k]='\0';
		puts(c);
	}
} 

Double click to view unformatted code.


Back to problem 22