首页 > 解决方案 > 代码一起询问所有测试用例的输入,而不是一个一个地为每个测试用例提供输出

问题描述

#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--){
    int n, k;
    cin >> n >> k;
    string s="", subs(k, '*');
    cin >> s;
    size_t found = s.find(subs);
    if(found!=string::npos){
        cout << "YES" << "\n";
    }
    else{
        cout << "NO" << "\n";
    }
}
return 0;
}

此代码一次获取所有测试用例的输入,而不是输入一个测试用例并为其提供输出,然后询问下一个测试用例的输入。

标签: c++stringsubstringsize-t

解决方案


推荐阅读