http://acm.hust.edu.cn/vjudge/contest/122814#problem/A
匹配到字符串就输出,水题,主要是substr的运用
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("! ") #define MAXN 205 #define MAX(a,b) a>b?a:b #define blank pf(" ") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue #define INF 0x3f3f3f3f int n,m; int main() { int i,j; string str; while(cin>>str) { int len = str.size(); for(i=0;i<len;i++) { if(len-i>=4) { string tmp = str.substr(i,4); if(tmp == "iPad" || tmp == "iPod") pf("MAI MAI MAI! "); else if(tmp == "Sony") pf("SONY DAFA IS GOOD! "); } if(len-i>=5) { string tmp = str.substr(i,5); if(tmp == "Apple") pf("MAI MAI MAI! "); } if(len-i>=6) { string tmp = str.substr(i,6); if(tmp == "iPhone") pf("MAI MAI MAI! "); } } } return 0; }