View Code of Problem 22

#include<stdio.h>
#include<string.h>
int main(){
	char a[1000];
	char b[1000];
	char c[1000];
	while(scanf("%s",a)!=EOF){
		scanf("%s",b);
		int k=0;
		for(int i=0;i<strlen(a);i++){
			for(int j=0;j<strlen(b);j++){
				if(a[i]==b[j]){
					c[k++]=a[i];
					b[j]='*';//  核心 只要找到一个相同的就把B中相同的部分置* 
					break; 
				}
			}	
		}
		//用一个冒泡排序输出
		char t;
		for(int i=0;i<k-1;i++){
			for(int j=0;j<k-i-1;j++){
				if(c[j]>c[j+1]){
					t=c[j];
					c[j]=c[j+1];
					c[j+1]=t;
				} 
			}
		} 
		c[k]='\0';
		puts(c);
	
	}
	
	
	return 0;
}

Double click to view unformatted code.


Back to problem 22