View Code of Problem 22

#include<stdio.h>
#include<string.h>
#include<stdlib.h> 
int main()
{
	char a[1000],b[1000],temp;
	char same[1000]={0}; 
	int i,j,l=0;
	while(gets(a)!=NULL)
	{   
	    scanf("%s",b);getchar();
	   // puts(a);
	   // puts(b);
		for(i=0;i<strlen(a);i++)
		{		for(j=0;j<strlen(b);j++)
			{
				if(a[i]==b[j]){
				
                 same[l++]=a[i]; b[j]='0';//k[l]='\0';
				 break;}
		
			}
		}
		for(i=0;i<l;i++)
		{ for(j=i;j<l;j++)
		   {
		   	if(same[i]>same[j])
		   	 {
			 temp=same[i];
		   	 same[i]=same[j];
		   	 same[j]=temp;}
		   }
		}
	    printf("%s\n",same);
	    same[1000]={0};
		l=0;
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:9:2: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
  while(gets(a)!=NULL)
  ^
Main.c:35:17: error: expected expression before '{' token
      same[1000]={0};
                 ^
*/

Double click to view unformatted code.


Back to problem 22