Advertisement
lily09290110

有優先權的+-*(無/yo~)計算機cc

Jan 7th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<math.h>
  5. int main()
  6. {
  7. int count=0,i=0,flag=0,j;
  8. char stack_o[20];
  9. double stack_sub[20],temp;
  10. do
  11. {
  12. scanf("%lf",&stack_sub[i]);
  13. scanf("%c",&stack_o[i]);
  14. if(flag==1)
  15. {
  16. stack_sub[count]*= stack_sub[count+1];
  17. stack_sub[count+1]=0;
  18. stack_o[count]='+';
  19. flag=0;
  20. }
  21. if(stack_o[i]=='*')
  22. {
  23. count=i;
  24. flag=1;
  25. }
  26. i++;
  27. }while(stack_o[i-1]!='=');
  28. temp=stack_sub[0];
  29. for(j=0;j<i;j++)
  30. {
  31. switch(stack_o[j])
  32. {
  33. case '+':temp+=stack_sub[j+1];
  34. break;
  35. case '-':temp-=stack_sub[j+1];
  36. break;
  37. case '=':printf("ans=%2.lf\n",temp);
  38. break;
  39. }
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement