我正在做我的C ++作业,但我无法弄清楚算法。
我必须制作一个使用字符串操作的程序。
字符串和运算符(+和*)应该以空格('')]区分>
和乘法先于加法
+)使用atoi将字符串更改为整数
例如:
输入:abc + b * 4 + xy * 2 + z
输出:abcbbbbxyxyz
到目前为止,这是我所做的↓
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include<sstream>
using namespace std;
enum classify {NUMBER, STRING, OPERATION, SPACE};
int char_type(string c)
{
if (c >= "0" && c <= "9") return NUMBER;
else if (c == "*" || c == "+") return OPERATION;
else if (c == " ") return SPACE;
else return STRING;
}
int main(void)
{
string input;
getline(cin, input);
istringstream token(input);
string buffer;
while (getline(token, buffer, ' '))
{ after I classify them using enum, how can I
let the computer to know "multiplication first"? }
}
我正在做我的C ++作业,但是我无法弄清楚算法。我必须编写一个使用字符串操作的程序。字符串和运算符(+和*)应该以空格('')和...
算法:
我不知道算法。
我实际上是C ++的新手,所以我很难理解Toggy Smith的代码