标签:
1 # include<cstdio> 2 # include<iostream> 3 # include<cstring> 4 using namespace std; 5 struct node{ 6 int value; 7 int next; 8 }a[500]; 9 char c[100]; 10 int main(){ 11 char s[500]; 12 while(scanf("%s",s)!=EOF){ 13 int l=strlen(s); 14 int i=0,j=0,k=0; 15 for(i=0;i<l;i++) 16 { 17 int sum=0; 18 while(s[i]>=‘0‘ && s[i]<=‘9‘) 19 { 20 sum=sum*10+s[i]-‘0‘; 21 i++; 22 } 23 a[j].value=sum; 24 a[j].next=j+1; 25 j++; 26 if(i<l) {c[k]=s[i];k++;} 27 } 28 a[j-1].next=-1; 29 k=0; 30 for(i=0;i<j-1;){ 31 if(c[k]==‘*‘) { 32 int cur=a[i].next; 33 a[i].value=a[i].value*a[cur].value; 34 a[i].next=a[cur].next; 35 c[k]=‘#‘; 36 } 37 else if(c[k]==‘/‘) 38 { 39 int cur=a[i].next; 40 a[i].value=a[i].value/a[cur].value; 41 a[i].next=a[cur].next; 42 c[k]=‘#‘; 43 } 44 else{ 45 i=a[i].next; 46 } 47 if(i==-1) break; 48 k++; 49 50 } 51 i=0; 52 int sum=a[i].value; 53 int a1=0,b1=0; 54 k=0; 55 i=a[i].next; 56 while(i!=-1) 57 { 58 b1=a[i].value; 59 while(c[k]==‘#‘) 60 k++; 61 if(c[k]==‘+‘) sum=sum+b1; 62 else sum=sum-b1; 63 k++; 64 i=a[i].next; 65 } 66 cout<<sum<<endl; 67 } 68 return 0; 69 }
上交的题真的都好难啊 呜呜 回头再看看
标签:
原文地址:http://www.cnblogs.com/dreamer123/p/5178557.html