求助大佬,为什么只能过两个测试点?(悬赏关注)
查看原帖
求助大佬,为什么只能过两个测试点?(悬赏关注)
1520634
Henryonly楼主2025/1/12 18:45
#include<stdio.h>
#include<string.h>
void find(char*word,char*article,int*num,int*position)
{
    char repository[100000][20];
    int count=0,counting=0,flag=0,finger=0;
    for(unsigned int i=0;i<strlen(article)+1;i++)
    {
        if(article[i]!=' '&&article[i]!='\0')
        {
            repository[count][counting]=article[i];
            counting++;
        }
        else
        {
            repository[count][counting]='\0';
            count++;
            counting=0;
        }
    }
    for(int i=0;i<count;i++)
    {
        if(strcmp(word,repository[i])==0&&flag==0)
        {
            (*num)++;
            flag=1;
            *position=finger;
        }
        if(strcmp(word,repository[i])==0&&flag==1)
        {
            (*num)++;
        }
        finger+=strlen(repository[i])+1;
    }
}
void strlwry(char *wowuyule)
{
    int i=strlen(wowuyule);
    for(int j=0;j<i;j++)
    {
        if(wowuyule[j]>='A'&&wowuyule[j]<='Z')
        {
            *(wowuyule+j)+=32;
        }
    }
}
int main()
{
    char word[100]={'\0'},article[1000010]={'\0'};
    int numA=0,numB=0;
    int *num=&numA,*position=&numB;
    scanf("%s",word);
    getchar();
    fgets(article,sizeof(article),stdin);
    strlwry(word);
    strlwry(article);
    find(word,article,num,position);
    if(*num==0)
    {
        printf("-1");
    }
    else
    {
        printf("%d %d",*num,*position);
    }
    return 0;
}
2025/1/12 18:45
加载中...