Accepted
/in/foo.cc: In function 'char find_unused(bool*)': /in/foo.cc:14:17: warning: array subscript has type 'char' [-Wchar-subscripts] if (!u[c]) return c; ^ /in/foo.cc: In function 'int count_unused(bool*)': /in/foo.cc:21:25: warning: array subscript has type 'char' [-Wchar-subscripts] cnt += (int) u[c]; ^ /in/foo.cc: In function 'int main()': /in/foo.cc:36:19: warning: array subscript has type 'char' [-Wchar-subscripts] if (m[b[i]] != 0 && m[b[i]] != a[i]) err(); ^ /in/foo.cc:36:35: warning: array subscript has type 'char' [-Wchar-subscripts] if (m[b[i]] != 0 && m[b[i]] != a[i]) err(); ^ /in/foo.cc:37:15: warning: array subscript has type 'char' [-Wchar-subscripts] m[b[i]] = a[i]; ^ /in/foo.cc:38:20: warning: array subscript has type 'char' [-Wchar-subscripts] used_a[a[i]] = true; ^ /in/foo.cc:39:20: warning: array subscript has type 'char' [-Wchar-subscripts] used_b[b[i]] = true; ^ /in/foo.cc:48:12: warning: array subscript has type 'char' [-Wchar-subscripts] m[b] = a; ^ /in/foo.cc:53:19: warning: array subscript has type 'char' [-Wchar-subscripts] if (m[c[i]] == 0) err(); ^ /in/foo.cc:54:22: warning: array subscript has type 'char' [-Wchar-subscripts] d[i] = m[c[i]]; ^
代码
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
const int MaxN = 1005;
char m[128];
bool used_a[128], used_b[128];
char a[MaxN], b[MaxN], c[MaxN], d[MaxN];
char find_unused(bool *u) {
for (char c = 'a'; c <= 'z'; ++c) {
if (!u[c]) return c;
}
return -1;
}
int count_unused(bool *u) {
int cnt = 0;
for (char c = 'a'; c <= 'z'; ++c) {
cnt += (int) u[c];
}
return cnt;
}
void err(void) {
printf("ERROR\n");
exit(0);
}
int main(void) {
scanf("%s\n%s\n%s\n", a, b, c);
int n = strlen(a);
for (int i = 0; i < n; ++i) {
if (m[b[i]] != 0 && m[b[i]] != a[i]) err();
m[b[i]] = a[i];
used_a[a[i]] = true;
used_b[b[i]] = true;
}
if (count_unused(used_a) != count_unused(used_b))
err();
if (count_unused(used_a) == 25) {
char a = find_unused(used_a);
char b = find_unused(used_b);
m[b] = a;
}
n = strlen(c);
for (int i = 0; i < n; ++i) {
if (m[c[i]] == 0) err();
d[i] = m[c[i]];
}
printf("%s\n", d);
return 0;
}