View Code of Problem 22

#include <iostream>
using namespace std;

int main(){
  char a[101],b[101],len_a,len_b,s,ans[101];
  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:7:21: error: 'strlen' was not declared in this scope
     len_a = strlen(a);
                     ^
Main.cc:11:20: warning: left operand of comma operator has no effect [-Wunused-value]
       for(int k=0;k<len_b,k++){
                    ^
Main.cc:11:30: error: expected ';' before ')' token
       for(int k=0;k<len_b,k++){
                              ^
Main.cc:13:18: warning: array subscript has type 'char' [-Wchar-subscripts]
           ans[s++] = a[j];
                  ^
*/

Double click to view unformatted code.


Back to problem 22