在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#include <iostream> #include <string> #include <vector> using namespace std; void part(string _str, vector<int> &_num, vector<char> &_op) { int sum = 0; unsigned int i = 0; while (i < _str.length()) { if ('0' <= _str.at(i) && _str.at(i) <= '9') //还原连续的数字 sum = sum * 10 + (_str.at(i) - '0'); else { _num.push_back(sum); _op.push_back(_str.at(i)); sum = 0; } i++; } //判断最后一个字符是否是数字 if (0 != sum) _num.push_back(sum); } int main() { vector<int> num(0); vector<char> op(0); string str; cin >> str; part(str, num, op); //输出测试 for (unsigned int i = 0; i < num.size(); i++) cout << num.at(i) << " "; cout << endl; for (unsigned int i = 0; i < op.size(); i++) cout << op.at(i) << " "; return 0; } 输入:
输出:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论