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];
    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;
        sort(t,t+k);
        for(int i = 0;i<k;i++) cout<<t[i];
        cout<<endl;
    }
    return 0;
}
/*
Main.cc: In function 'int main()':
Main.cc:11:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<strlen(a);i++){
                  ^
Main.cc:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<strlen(b);j++){
                      ^
Main.cc:35:19: error: 'sort' was not declared in this scope
         sort(t,t+k);
                   ^
*/

Double click to view unformatted code.


Back to problem 22