2178 表示式運算Cuties

2022-05-03 10:33:17 字數 1217 閱讀 3957

時間限制: 1 s

空間限制: 32000 kb

題目等級 : 大師 master

題解給出乙個表示式,其中運算子僅包含+,-,*,/,^要求求出表示式的最終值

資料可能會出現括號情況 還有可能出現多餘括號情況

資料保證不會出現》maxlongint的資料

資料可能回出現負數情況

輸入描述 input description

僅一行,即為表示式

輸出描述 output description

僅一行,既為表示式算出的結果

樣例輸入 sample input

(2+2)^(1+1)

樣例輸出 sample output

資料範圍及提示 data size & hint

表示式總長度<=30

分類標籤 tags 點此展開 

字串處理

題解:

字串表示式運算的模板

ac**:

#include#include

using

namespace

std;

const

int n=52

;char

s[n],sym[n];

inti,p,l,cnt,num[n];

bool

can()

int fpow(int a,int

b)void

push()

void

pop()

}int

main()

sym[++p]='('

;

for(;cnt>=0;cnt--) s[++l]=')'

;

for(i=1;i<=l;)

int x=0

;

while(s[i]>='

0'&&s[i]<='

9') x=x*10+s[i++]-'0'

; num[p]=x;

do

else

i++;

}while(i<=l&&s[i-1]==')'

); }

printf("%d

",num[0

]);

return0;

}

模板 表示式運算

這些都是emmmm 給出乙個表示式,其中運算子僅包含 要求求出表示式的最終值資料可能會出現括號情況 還有可能出現多餘括號情況資料保證不會出現 maxlongint的資料。資料可能回出現負數情況 2 2 1 1 16真的是超級麻煩emmmm,今天考試的時候看了看接著就棄了。說實話這個真不應該棄掉,但是...

JS數學表示式運算

在專案中經常碰到js精度問題,且常用到連續的運算 故寫了個簡單的數學表示式計算,僅支援 計算結果 math.express 3 1 2.3 6 3 5 1 1 1 2 1.9 math.express.add 1.2,3.33 4.53 math.express function 兩個浮點數求和 e...

表示式求值(整數運算)

可以進行10以上的加減乘除以及括號運算。十一瘋了七天,趕緊補完了 如下 include include include include include include using namespace std define clr a,b memset a,b,sizeof a mapd 字元到數字的...