View Code of Problem 22

#include<stdio.h>
#include<string.h>
int main(){
	char s1[1000],s2[1000],s3[1000];
	char t;
	int k;
	while(gets(s1)!=NULL){
		//scanf("%s",&s2);
		gets(s2);
		int l1,l2;
		l1=strlen(s1);
		l2=strlen(s2);
		
		k=0;
		for(int i=0;i<l1;i++){
			for(int j=0;j<l2;j++){
				if(s1[i]==s2[j]){
					s3[k++]=s1[i];
					s2[j]='*';
					break; //这里把所有的相同元素存贮进了s3; 
				}		
			}
		}
		//接着先排序 然后输出即可
		for(int i=0;i<k-1;i++){
			for(int j=i+1;j<k;j++){
				if(s3[i]>s3[j]){
					t=s3[i];
					s3[i]=s3[j];
					s3[j]=t;
				}
			}
		} 
		//使用完要清0 
		
		puts(s3);	
	}	
	return 0;
}

Double click to view unformatted code.


Back to problem 22