【发布时间】:2020-09-26 15:28:54
【问题描述】:
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int count = 0;
vector<string> v;
string resp;
cin >> resp;
v.push_back(resp);
for(int i = 0; i < v.size(); i++){
if(find(v.begin(), v.end(), "xy") != v.end()){
count++;
}
cout << count << endl;
}
return 0;
}
我想在多个测试用例的字符串中找到字符“xy”。 对于输入 xy,我的计数值正确输出为 1。
但是对于输入 xyxxy 而不是 2 它给出的值为 0 它只找到一次值,但我想检查整个字符串中 xy 的计数
我也尝试使用 substring 函数,但它失败了
【问题讨论】:
-
为什么要包含非标准的包含文件?
标签: c++ string data-structures stl substring