/ Randle /

记录详情

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]];
                      ^
# 状态 耗时 内存占用
#1 Accepted 3ms 384.0 KiB
#2 Accepted 3ms 372.0 KiB
#3 Accepted 3ms 384.0 KiB
#4 Accepted 4ms 336.0 KiB
#5 Accepted 3ms 376.0 KiB
#6 Accepted 3ms 356.0 KiB
#7 Accepted 3ms 380.0 KiB
#8 Accepted 3ms 348.0 KiB
#9 Accepted 3ms 380.0 KiB
#10 Accepted 3ms 348.0 KiB

代码

#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;
}

信息

递交者
类型
递交
题目
字符串问题 T1
题目数据
下载
语言
C++
递交时间
2017-10-19 19:48:53
评测时间
2017-10-19 19:48:53
评测机
分数
100
总耗时
35ms
峰值内存
384.0 KiB