1 条题解
-
0
韩东志 LV 7 @ 2 天前
#include <iostream>
#include <string>
using namespace std;int main() {
string str, substr;
// 读取主串
getline(cin, str);
// 读取子串
getline(cin, substr);int count = 0;
size_t pos = 0;
while ((pos = str.find(substr, pos)) != string::npos) {
count++;
pos += substr.length();
}
if (count == 0) {
cout << -1 << endl;
} else {
cout << count << endl;
}
return 0;
}
- 1
信息
- ID
- 1093
- 难度
- 7
- 分类
- (无)
- 标签
- 递交数
- 298
- 已通过
- 59
- 通过率
- 20%
- 被复制
- 2
- 上传者