View Code of Problem 22

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	char a[1000],b[1000],same[1000],temp;
        int i,j,len1,len2,l;
    	while(gets(a)!=NULL)
    	{    
    	     gets(b); 
    	    //scanf("%s",b);getchar(); 错!!!! 
             l=0;
    		 len1=strlen(a);
    	     len2=strlen(b); 
           for(i=0;i<len1;i++)
    			{
    				for(j=0;j<len2;j++)
						if(a[i]==b[j])
						{
							same[l++]=b[j]; b[j]='0';//k[l]='\0';
							break;
						}
					same[l]='\0';
				}
    			
    		
    		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;}		
    	 //puts(same); // 括号多错!! 
    	 for(i=0;i<l;i++)
    	 {
    	 printf("%c",same[i]);}
    	 printf("\n");
    	}
    	return 0;
    }

Double click to view unformatted code.


Back to problem 22