View Code of Problem 22

#include<stdio.h>
#include<string.h>
int main(){

	char str1[1000],str2[1000];
//	while(scanf("%s%s",str1,str2)!=EOF){
	while(gets(str1)!=NULL&&gets(str2)!=NULL){
		int i,j,k,a[126]={0},b[126]={0};
		for(i=0;str1[i]!='\0';i++){
			a[str1[i]]++;
		}
		for(j=0;str2[j]!='\0';j++){
			b[str2[j]]++;
		}
		for(k=0;k<126;k++){
			if(a[k]>=1&&b[k]>=1){
				printf("%c",k);
				a[k]--;
				b[k]--;
				k--;			
			}		
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22