View Code of Problem 22

#include <iostream>
using namespace std;

int main(){
  char a[101],b[101],ans[101];
  int len_a,len_b,s;
  while(scanf("%s\n%s",a,b)!=EOF){
    len_a = strlen(a);
    len_b = strlen(b);
    s = 0;
    for(int j=0;j<len_a;j++){
      for(int k=0;k<len_b;k++){
        if(a[j]==b[k]){
          ans[s++] = a[j];
        }
      }
    }
    //排序
    for(int j=0;j<s;j++){
      for(int k=0;k<s-1-j;k++){
        if(ans[k]>ans[k+1]){
          char tmp = ans[k];
          ans[k] = ans[k+1];
          ans[k+1] = tmp;
        }
      }
    }
    
    printf("%s\n",ans);
  }
  return 0;
}
/*
Main.cc: In function 'int main()':
Main.cc:8:21: error: 'strlen' was not declared in this scope
     len_a = strlen(a);
                     ^
*/

Double click to view unformatted code.


Back to problem 22