编写程序,读入一行恰好包含一个加号、减号、乘号、或除号的表达式,输出它的值。两个运算数均为不超过100的非负整数。运算数和运算符可以紧挨着,也可以用一个或多个空格、TAB隔开。行首末尾均可以有空格。提示:选择适当的输入方法可以将问题简化。
样例输入:1+1
样例输出:2
样例输入:2 -5
样例输出:-3
样例输入:0 * 1982
样例输出:0
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
int main(int argc, char *argv[])
{
system("color 0a");
char a,c;
int x=0,y=0,s=0;
while( (a=getchar())!='\n' )
{
if( isdigit(a) )
{
s*=10;
s+=a-'0';
}
else if( a=='+' || a=='-' || a=='*' || a=='/' )
{
x=s;
c=a;
s=0;
}