编译失败怎磨回事
查看原帖
编译失败怎磨回事
1068224
a15801016376楼主2023/12/3 08:55

跟我说gets未阐明,你是否想用fgets 附代码:

#include<iostream>
#include<cstring>
using namespace std;
void strlowr(char *str){
    for(int i=0;i<str[i];i++){
        if(str[i]>96&&str[i]<123){
            str[i]+='A'-'a';
        }
        else
            continue;
    }
}
int main(){
    char essay[100001],target[100],*p,*q;
    int local=-1,sum=0,len;
    bool flag=false;
    gets(target);
    strlowr(target);
    gets(essay);
    strlowr(essay);
    p=essay;
    len=strlen(target);
    for(;q==strstr(p,target);){
        if(q!=nullptr&&
           (q==essay||*(q-1)==' ')&&(*(q+len)=='\0'||*(len+q)==' ')){
            sum++;
            if(!flag){
                flag=true;
                local=q-essay;
            }
        }
        p=q+len;
    }
    if(flag){
        cout<<sum<<" "<<local<<endl;
    }
    else
        cout<<local<<endl;
    return 0;
}
2023/12/3 08:55
加载中...