Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
34982 | 吴泽贤 | 统计特定单词数 | C++ | Accepted | 5 MS | 764 KB | 651 | 2022-08-03 14:57:28 |
#include <iostream> 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; }