求助:C语言 8-10测试点RE
查看原帖
求助:C语言 8-10测试点RE
928252
Catherine666楼主2023/7/11 16:44
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct Node
{
    char w[1000];
    int count;
    int location;
} word[100000], word1[100000];
char s[15];
char line[1000001];
int main()
{
    int flag = 0;
    gets(s);
    int l1 = strlen(s);
    for (int i = 0; i < l1; i++)
    {
        if (s[i] >= 'A' && s[i] <= 'Z')
            s[i] = s[i] + 32;
    }

    gets(line);
    int l = strlen(line);
    for (int i = 0; i < l; i++)
    {
        if (line[i] >= 'A' && line[i] <= 'Z')
            line[i] = line[i] + 32;
    }

    int j = 0, k = 0;
    word[0].location = 0;
    for (int i = 0; i < l; i++)
    {
        if (isalpha(line[i]))
        {
            if (k == 0)
                word[j].location = i;
            word[j].w[k++] = line[i];
        }
        else
        {
           word[j].w[k]='\0';
            word[j++].count = 1;
            k = 0;
        }
    }
    int loc = 0, mark = 0, count = 0;
    for (int i = 0; i < j; i++)
    {
        if (!strcmp(s, word[i].w))
        {
            if (flag == 0)
            {
                loc = word[i].location;
                flag = 1;
                mark = 1;
            }
            count++;
        }
    }
    if (mark == 0)
        printf("-1\n");
    else
        printf("%d %d\n", count, loc);
    return 0;
}
2023/7/11 16:44
加载中...