當前位置:編程學習大全網 - 網絡軟體 - 表達式求值 2013年noip全國聯賽普及組

表達式求值 2013年noip全國聯賽普及組

使用壹個棧存儲運算符 最後運算符逐個出棧 進行相應的運算 不過壹定要註意 運算的優先級 還要註意要壹邊計算壹邊取摸

#include<cstdio>

#include<cstring>

#include<cmath>

#include<iostream>

#include<cstdlib>

#include<algorithm>

using?namespace?std;

const?int?kela=1000010,momo=10000;

char?s[kela];

int?main()

{

freopen("t.in","r",stdin);

freopen("t.out","w",stdout);

int?i,a=1,b=0,ans=0;

gets(s);

for(i=0;i<strlen(s);++i)

switch(s[i])

{

case?'+':ans=(ans+a*b)%momo;a=1;b=0;break;

case?'*':a=a*b%momo;b=0;break;

default:b=(b*10+s[i]-'0')%momo;

}

printf("%d",(ans+a*b)%momo);

fclose(stdin);fclose(stdout);

return?0;

}

  • 上一篇:地下城與勇士中85版本刷圖劍聖加點,暴力的
  • 下一篇:css設置滾動條顏色與樣式以及如何去掉與隱
  • copyright 2024編程學習大全網