求助:70分 TLE最后三个点
查看原帖
求助:70分 TLE最后三个点
793290
kINo204楼主2025/1/19 23:30

代码如下

#include "stdio.h"
#include "string.h"
#include "ctype.h"

int main() {
    char word[11], article[1000001];
    gets(word);
    gets(article);

    char next[100];
    int cnt = 0, first = -1, pos = 0, len;
    do {
        while (article[pos] == ' ') pos++;
        len = sscanf(article + pos, "%s", next); // next <- next word
        if (len != EOF) {
            len = strlen(next);
            int success = 1;
            if (len != strlen(word)) {
                success = 0;
            } else {
                for (int i = 0; i < strlen(word); i++) {
                    if (tolower(word[i]) != tolower(next[i])) {
                        success = 0;
                        break;
                    }
                }
            }

            if (success) {
                cnt++;
                if (first == -1) first = pos;
            }

            pos += len;
        }
    } while (len != EOF);

    if (first == -1) {
        printf("-1\n");
    } else {
        printf("%d %d\n", cnt, first);
    }

    return 0;
}
2025/1/19 23:30
加载中...