View Code of Problem 22

#include<stdio.h>
#include<string.h>
#include<math.h>
void main(){
  char a[1010],b[1010];
  while(scanf("%s %s",a,b)!=EOF){
    int a1[26]={0},b1[26]={0};
    int l1=strlen(a),l2=strlen(b);
    int m=fmax(l1,l2);
    for(int i=0;i<m;i++){
      if(i<l1)
      	a1[a[i]-'a']++;
      if(i<l2)
        b1[b[i]-'a']++;
    }
    for(int i=0;i<26;i++){
      if(a1[i] && b1[i]){
        for(int j=1;j<=fmin(a1[i],b1[i]);j++)
          printf("%c",'a'+i);
      }
    }
    printf("\n");
  }
}
    

Double click to view unformatted code.


Back to problem 22