View Code of Problem 22

#include<iostream>
using namespace std;
int main() {
	string a,b,c;
	while(cin>>a>>b) {
		c="";
		for(int i=0; i<a.length(); i++) {
			for(int j=0; j<b.length(); j++) {
				if(a[i]==b[j]&&a[i]!=' ') {
					c+=a[i];
					b[j]=' ';
					break;
				}
			}
		}
		//排序
		for(int i=0; i<c.length()-1; i++) {
			for(int j=i+1; j<c.length(); j++) {
				if(c[i]>c[j]) swap(c[i],c[j]);
			}
		}
		cout<<c<<endl;
	}
}

Double click to view unformatted code.


Back to problem 22