标签:get define rip png stdin class ble 运算 opp
[Description]
小 77 是 2017 级信奥班的成员,因为哲学而出名。
小 77 的数学老师信奉大力刷题出奇迹,于是给他们出了 INF 道简单的数字运算题。每道题
都只包含加号,乘号和十以内的数字。虽然题很简单,但是小 77 觉得这么多题简直是浪费
时间,而他还要忙着钻研哲学,于是决定让你写一个程序自动运算。
[Input]
一行,一个只包含加号,乘号和十以内的数字(即数字范围为[0, 9])的算式。
[Output]
一行一个整数,对算式求值的结果。
[Sample]

[Tips]
数字,符号中间可能有一个或多个空格,也有可能没有空格。
算式去除空格后的长度不超过 100, 000。平均情况下每两个符号间有两个空格。
答案不会超过 64 位有符号整数范围。
记录两个符号和两个数字,每次是乘号就乘上。
我的栈是没必要用的,但是懒得改了。
代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define il inline
#define db double
using namespace std;
int fu[1000045],top;
ll num[1000045],topp;
int main()
{
freopen("eval.in","r",stdin);
freopen("eval.out","w",stdout);
char ch=getchar();
ll ans=0;
while(ch!=EOF)
{
if(ch==‘+‘)
fu[++top]=1;
if(ch==‘*‘)
fu[++top]=2;
if(ch>=‘0‘&&ch<=‘9‘)
{
num[++topp]=ch-‘0‘;
if(fu[top]==2)
{
ll s=num[topp]*num[topp-1];
num[--topp]=s;
top--;
}
}
ch=getchar();
}
for(int i=1;i<=topp;i++)
ans+=num[i];
printf("%lld\n",ans);
return 0;
}
标签:get define rip png stdin class ble 运算 opp
原文地址:http://www.cnblogs.com/gshdyjz/p/7700060.html