社区讨论
好水,有错,但通过了,为什么
P1308[NOIP 2011 普及组] 统计单词数参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi5i21q1
- 此快照首次捕获于
- 2025/11/19 12:25 4 个月前
- 此快照最后确认于
- 2025/11/19 12:25 4 个月前
CPP
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
char a[1000005],word[11],t[11];
int main(){
gets(word);
gets(a);
int ans=0;
int pos=-1;
int lena=strlen(a);
int lenw=strlen(word);
for(int i=0;i<lena;i++)a[i]=tolower(a[i]);
for(int i=0;i<lenw;i++)word[i]=tolower(word[i]);
for(int i=0;i+lenw<lena;i++) {
if(!(i-1>=0&&a[i-1]==' '&&i+lenw<lena&&a[i+lenw]==' '))continue;
int j;
for(j=0;j<lenw;j++)t[j]=a[i+j];
t[j]='\0';
if(!strcmp(word,t)){
ans++;
if(pos==-1)pos=i;
}
}
if(ans)cout<<ans<<" "<<pos;
else cout<<"-1";
return 0;
}
输入er
er er er er er er er
样例输出也没过
回复
共 1 条回复,欢迎继续交流。
正在加载回复...