标签:字符串 pad out npos iphone 函数 str show ++i
STL string
没有能查多个字符串的函数,但可以查多个字符。
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const string a[] = {"Apple", "iPhone", "iPod", "iPad", "Sony"};
string str;
inline void cal(int pos) {
for (int i = 0; i < 5; ++i) {
if (str.substr(pos, a[i].size()) == a[i]) {
if (i == 4)
cout << "SONY DAFA IS GOOD!\n";
else
cout << "MAI MAI MAI!\n";
return;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
while (getline(cin, str)) {
int pos = 0;
while ((pos = str.find_first_of("AiS", pos)) != string::npos) {
cal(pos);
++pos;
}
}
return 0;
}
标签:字符串 pad out npos iphone 函数 str show ++i
原文地址:https://www.cnblogs.com/mostiray/p/13233196.html