View Code of Problem 22

#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
using namespace std;
int main(){
    char a[999],b[999],t[999],temp;
    int k = 0;
    while(cin.getline(a,999)&&cin.getline(b,999)){
        k = 0;
    for(int i=0;i<strlen(a);i++){
        for(int j=0;j<strlen(b);j++){
            if(b[j]==a[i]){
                t[k++]=b[j];
                b[j]='#';
            break;
            }
        }
    }
            for(int i=0;i<k+1;i++){
                int min=i;
                for(int j=i;j<k+1;j++){
                if(t[j]<t[min]){
                    temp = t[j];
                    t[j] = t[min];
                    t[min] = temp;
                }
                }
            }
             for(int i=0;i<k+1;i++){
                 cout<<t[i];
                 t[i]=NULL;
                 
             }
    
        cout<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 22