指针+strstr
1655: 某人好想AC哦~
Time Limit: 1 Sec Memory Limit: 128 MB
給你一個字符串S和一個字符串的P,希望你從s中刪除p(注意一點的是,刪除p后,可能又會形成一個新的p)
Input
一行2個字符串S,P;(長度小于100)
Output
輸出S刪除P后的結果
Sample Input
woyaowwwaaaac wa
Sample Output
woyaoac
HINT
解釋;
第一步:woyaowwwaaaac—>woyaowwaaac
第二步:woyaowwaaac---->woyaowaac
第三步:woyaowaac—>woyaoac
Source
代碼~:
下面是我同學寫的我要來學習的:
#include <iostream> #include <stdio.h> #include <algorithm> #include <string> using namespace std; int main() {string s,p;while(cin>>s>>p){int len=p.length();while(s.find(p)!=string::npos){int pos=s.find(p);s.erase(s.begin()+pos,s.begin()+pos+len);}cout<<s<<endl;}return 0; } 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: 数字统计2(依然是数组下标法)
- 下一篇: 二叉树的先序建树后序输出