#include<iostream> #include<string> #include<algorithm> using namespace std; int main() { int t; string s1, s2; char c[100] = { 0 }; cin >> t; while (t--) { getchar(); cin >> s1 >> s2; int k = 0; for (int i = 0; i < s1.size(); i++) { for (int j = 0; j < s2.size(); j++) { if (s1[i] == s2[j]) { c[k++] = s2[j]; s2[j] = '0';//防止重复 break; } } } if (k == 0) cout << -1 << endl; else{ k--; sort(c, c + k); for (int i = 0; i < strlen(c); i++) { if (i == strlen(c) - 1) cout << c[i] << endl; else cout << c[i]; } } } } /* Main.cc: In function 'int main()': Main.cc:15:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < s1.size(); i++) ^ Main.cc:17:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int j = 0; j < s2.size(); j++) ^ Main.cc:30:37: error: 'strlen' was not declared in this scope for (int i = 0; i < strlen(c); i++) ^ */ |
Double click to view unformatted code.