/*
三、题目描述(50分):
通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。
输入字符串的格式为:“操作数1 运算符 操作数2”,“操作数”与“运算符”之间以一个空格隔开。
补充说明:
1. 操作数为正整数,不需要考虑计算结果溢出的情况。
2. 若输入算式格式错误,输出结果为“0”。
要求实现函数:
void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr);
【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出
示例
输入:“4 + 7” 输出:“11”
输入:“4 - 7” 输出:“-3”
输入:“9 ++ 7” 输出:“0” 注:格式错误
*/
#include <iostream>
#include <string>
using namespace std;
#define N 10
void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr)
{
char *pInput = const_cast<char *>(pInputStr);
char ch;
int index1 = 0;
int index2 = 0;
int index3 = 0;
char op1[N];
char op[N];
c
华为机试——通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串
最新推荐文章于 2016-09-05 16:49:52 发布