Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
27628 | 唐心 | 统计单词数 | C++ | Accepted | 62 MS | 6484 KB | 956 | 2022-06-07 11:29:25 |
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> using namespace std ; string lwr(string str) { for(int i = 0 ; i < str.length() ; i++) if(str[i] >= 'A' && str[i] <= 'Z') str[i] += 32; return str; } int main() { string sp ; string str ; int cnt = 0 ; int pos = -1 ; getline(cin,sp); getline(cin,str); str = lwr(str); sp = lwr(sp); str = ' '+str+' ' ; sp = ' '+sp+' ' ; for(int i = 0 ; i < str.length() ; i++){ int j = 0 ; for(j = 0; j < sp.length() ; j++ ){ if(str[i+j] != sp[j]) break ; } if(j == sp.length()){ cnt = cnt + 1; if(cnt == 1) pos = i ; } } if(cnt > 0) cout << cnt << " " << pos; else cout << pos; return 0 ; }