View Code of Problem 22

#include <stdio.h>
#include <string.h>
int main(){
  char a[1000];
  char b[1000];
  char c[1000];
  int i,j,k,len;
  char temp;
  while (gets(a) != NULL){
	  gets(b);
	  k=0;
    for(i=0;i<strlen(a);i++){
      for(j=0;j<strlen(b);j++){
		  if(a[i]==b[j]){
          c[k++]=a[i];
			b[j]='#';
		  }
      }
    
    }
	
    for(i=0;i<k;i++){
		for(j=i+1;j<k;j++){
			if(c[j]<c[i]){
				temp = c[i];
				c[i] = c[j];
				c[j] = temp;
			
			}
			
		
		}
	
	}
	c[k]='\0';
	puts(c);
	/*
	
	i=0;
	len=k;
		while(i<len){
			if(c[i]==c[i+1]){
				for(j=i;j<len;j++)
					c[j]=c[j+1];
				len--;
			}
			else
				i++;
		
		}
	
		
		c[len]='\0';
		puts(c);
		
  */
  }
 
 
return 0;
}

Double click to view unformatted code.


Back to problem 22