c语言,70分,6,8,10
查看原帖
c语言,70分,6,8,10
1439503
WarEpic楼主2024/10/15 19:59
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

char word[20], sentence[1000010][20];

int judge(int i)
{
    if(strlen(sentence[i]) != strlen(word)) return 0;
    else
    {   for (int j = 0; j < strlen(word); j++)
        {   if (tolower(word[j]) != tolower(sentence[i][j])) return 0;
        }
    }
    return 1;
}

int main()
{
    scanf("%s", word);
    getchar();
    char input[10000010];
    fgets(input, sizeof(input), stdin);
    int len = strlen(input);
    int index = 0, ch = 0, ans = 0;

    for (int i = 0; i < len; i++)
    {    if (input[i] == ' ' || input[i] == '\n')
        {   if(i==0){
                ans+=1;
                continue;
            }
            sentence[index][ch] = '\0';
            index += 1, ch = 0;
        }
        else
        {   sentence[index][ch] = input[i];
            ch += 1;
        }
    }

    int count = 0, position[1000000] = {0};
    for (int i = 0; i <= index; i++)
    {   if (judge(i))
        {   position[count] = i;
            count += 1;
        }
    }
    for (int i = 0; i < position[0]; i++) ans += strlen(sentence[i]) + 1;
    if (count == 0) printf("-1");
    else printf("%d %d", count, ans);

    return 0;
}
```c
2024/10/15 19:59
加载中...