pta编译器不支持gets(),改为cin.getline(s,85)。
#include<bits/stdc++.h>
using namespace std;
int main(){
int flagcout=0,cout=1,first=0,flag=0;
char s[85];
//gets(s); pta编译器不支持gets(),改为cin.getline(s,85);
cin.getline(s,85);
while(strcmp(s,".")!=0){
if(strstr(s,"chi1 huo3 guo1")){
if(flag==0){
first=cout;
}
flag=1;
flagcout++;
}
//gets(s);
cin.getline(s,85);
cout++;
}
printf("%d\n",cout-1);
if(flagcout==0){
printf("-_-#");
}else{
printf("%d %d",first,flagcout);
}
return 0;
}
该代码段展示了一个在pta编译器中因不支持gets()函数而改用cin.getline()读取字符串的例子。程序通过遍历输入的字符串,查找特定子串chi1huo3guo1,并记录出现次数和位置。最终输出相关信息。
503

被折叠的 条评论
为什么被折叠?



