View Code of Problem 22

#include<stdio.h>
#include<string.h>

int main (){
	char a[1000], b[1000];
	char c[1000];
	char temp;
	int k;
	while(gets(a) != NULL){
		gets(b);
		k = 0;
		for(int i = 0;i < strlen(a);i++){
			for(int j = 0;j < strlen(b);j++){
				if(a[i] == b[j]){
					c[k++] = a[i];
					b[j] = '#';
					break;		
				}
			}
		}
		
		c[k] = '\0';
		for(int i = 0;i < strlen(c);i++){
			for(int j = i + 1;j < strlen(c);j++){
				if(c[i]>c[j]){
					temp = c[i];
					c[i] = c[j];
					c[j] = temp;
				}
			}
		}
		
		puts(c);
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 22