判断字串

判断s2是否为s1的字串。若是则输出1,否则输出0

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s1;  cin >> s1;
    int n;  cin >> n;
    while (n --) {
        int num = 0;
        string s2;  cin >> s2;
        unsigned int m = s1.find(s2, 0);
        while (m != string::npos) {
            num ++ ;
            break;
        }
        if (num)    cout << 1 << endl;      //输出1表示s2为s1的字串 
        else    cout << 0 << endl;
    }
    return 0;
}

你可能感兴趣的:(String,子串)