课评: 转出学生归档(王子墨/张立坤/黄俊博)+ 周四班级总结 + 新生章梓皓档案 + C++示例代码
This commit is contained in:
30
C++代码/GESP考级/三级/202609分割字符串解法3.cpp
Normal file
30
C++代码/GESP考级/三级/202609分割字符串解法3.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define endl '\n'
|
||||
using namespace std;
|
||||
|
||||
string s;
|
||||
|
||||
|
||||
int main(){
|
||||
getline(cin, s);
|
||||
|
||||
string kg = "";
|
||||
int l = 0, r = 0;
|
||||
|
||||
while(true){
|
||||
kg = kg + ' ';
|
||||
if(s.find(kg, l) == string::npos){
|
||||
// 如果没有找到
|
||||
r = s.size() - 1;
|
||||
cout << s.substr(l, r - l) << endl;
|
||||
break;
|
||||
} else {
|
||||
// 找到了
|
||||
r = s.find(kg, l);
|
||||
cout << s.substr(l, r - l) << endl;
|
||||
l = r + kg.size();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user