编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3825 #1008. 出行请佩戴好字符串 Compile Error 0 0 ms 0 K C / 1.0 K s230026068 2023-11-25 16:58:19
显示原始代码
#include <stdio.h>
#include <string.h>

int min(int a, int b, int c) {
    if (a < b) {
        return (a < c) ? a : b;
    } else {
        return (b < c) ? b : c;
    }
}

int distance(char* str1, char* str2) {
    int m = strlen(str1);
    int n = strlen(str2);

    int dp[m + 1][n + 1];

    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0) {
                dp[i][j] = j;
            } else if (j == 0) {
                dp[i][j] = i;
            } else if (str1[i - 1] == str2[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1];
            } else {
                dp[i][j] = 1 + min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
            }
        }
    }
    return dp[m][n];
}

int similar(char* str1, char* str2, int x) {
    int distance = distance(str1, str2);
    return distance <= x;
}

int main() {
    char S[500000];
    char T[500000];
    int N;

    scanf("%s", S);
    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
        scanf("%s", T[i]);
    }
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (similar(S, T[i]), N) {
            count++;
        }
    }
    printf("%d", count);

    for (int i = 0; i < N; i++) {
        if (similar(S, T[i]), N) {
        } else {
            printf("%d", i + 1);
        }
    }
    return 0;
}

编译信息

/sandbox/1/a.c:40:23: error: called object type 'int' is not a function or function pointer
        int distance=distance(str1,str2);
                     ~~~~~~~~^
/sandbox/1/a.c:53:14: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
                scanf("%s",T[i]);
                       ~~  ^~~~
/sandbox/1/a.c:57:20: error: too few arguments to function call, expected 3, have 2
                if(similar(S,T[i]),N){
                   ~~~~~~~       ^
/sandbox/1/a.c:39:5: note: 'similar' declared here
int similar(char* str1,char* str2,int x){
    ^
/sandbox/1/a.c:64:20: error: too few arguments to function call, expected 3, have 2
                if(similar(S,T[i]),N){
                   ~~~~~~~       ^
/sandbox/1/a.c:39:5: note: 'similar' declared here
int similar(char* str1,char* str2,int x){
    ^
1 warning and 3 errors generated.