2 条题解
-
0
#include<string> #include<cctype> using namespace std; int Count(string key,string str) { int cnt =0,pos=0; while(true) { int t=str.find(key,pos); if(t==-1) { return cnt; } else { cnt++; pos= t+key.size()-1;//因为有空格说以一定要-1 去查 } } } string Lower(string s) { for(int i=0;i<=s.size()-1;i++) { s[i]=tolower(s[i]); } return s; } int main() { string key,str; getline(cin,key); getline(cin,str); key=Lower(key)+" ";//引用函数lower把字符串变成小写并尾部加空格再赋值 str=Lower(str)+" "; key.insert(0," ");//把字符串首位也加上空格 str.insert(0," "); if(str.find(key)==string::npos)//字符串查找 to { cout<<-1<<endl; } else { cout<<Count(key,str)<<' '<<str.find(key); } return 0; }
- 1
信息
- ID
- 1561
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 10
- 已通过
- 8
- 上传者