刷題 UVa 10252 Common Permutation 解答
Algorithm:
無腦暴力解即可
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(""); | |
} | |
} |
留言
張貼留言