#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;
}

输入:

1+6+1/4+5*3

输出:

1 6 1 4 5 3
+ + / + *

相关文章:

  • 2022-12-23
  • 2021-12-11
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-08-09
  • 2022-01-13
相关资源
相似解决方案