View Code of Problem 22

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int num[1000001];
int main() {
	char str[1001];
	char str2[1001];
	int i;
	while(gets(str)!=NULL) {
		int j=0;
		char res[100];
		int num[1000]= {0};
		gets(str2);
		for(i=0; i<strlen(str); i++) {
			num[str[i]]=1;
		}
		for(i=0; i<strlen(str2); i++) {
			if(num[str2[i]]==1) {
				num[str2[i]]=0;
				res[j]=str2[i];
				j++;
			}
		}
		sort(res,res+j);
		for(i=0; i<j; i++) {
			printf("%c",res[i]);
		}
		printf("\n");
	}
}

Double click to view unformatted code.


Back to problem 22