刷題 UVa 10252 Common Permutation 解答

Algorithm: 無腦暴力解即可
#include <algorithm>
#include <cstdio>
#include <cstring>
char a[2000];
char b[2000];
bool g(char *p) {
if (fgets(p, 2000, stdin) == NULL) return false;
p[strlen(p) - 1] = '\0';
return true;
}
int main(){
while(g(a) && g(b)){
int c1[128] = {}, c2[128] = {};
for (int i = 0; a[i] != '\0'; i++) c1[a[i]]++;
for (int i = 0; b[i] != '\0'; i++) c2[b[i]]++;
for (int i = 0; i < 128; i++) {
int v = std::min(c1[i], c2[i]);
for (; v > 0; v--) putchar(i);
}
puts("");
}
}
view raw 10252.cpp hosted with ❤ by GitHub

留言

熱門文章