http://acm.hdu.edu.cn/showproblem.php?pid=5007
纯属联系String的substr
当substr截取的长度小于写的话
string te; int n; te="Hellow"; cout << te.substr(3,5);
我试了下 打印出来的是low....
写的时候没去限制边界还是AC了
//#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <iomanip> #include <cmath> #include <map> #include <set> #include <queue> using namespace std; #define ls(rt) rt*2 #define rs(rt) rt*2+1 #define ll long long #define ull unsigned long long #define rep(i,s,e) for(int i=s;i<e;i++) #define repe(i,s,e) for(int i=s;i<=e;i++) #define CL(a,b) memset(a,b,sizeof(a)) #define IN(s) freopen(s,"r",stdin) #define OUT(s) freopen(s,"w",stdout) const ll ll_INF = ((ull)(-1))>>1; const double EPS = 1e-8; const double pi = acos(-1.0); const int INF = 100000000; int main() { string s; while(cin>> s ) { int len=s.size(); for(int i=0;i<len;i++) { string s4=s.substr(i,4); string s5=s.substr(i,5); string s6=s.substr(i,6); if(s4 == "iPod" || s4 == "iPad" || s5 == "Apple" || s6=="iPhone") puts("MAI MAI MAI!"); if(s4 == "Sony") puts("SONY DAFA IS GOOD!"); } } return 0; }
时间: 2024-10-15 14:14:28