fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<ctype.h>
  4. #include<string.h>
  5. typedef struct
  6. {
  7. int a[101];
  8. int top;
  9. }stack;
  10. void push(stack *s,int val);
  11. void pop(stack *s);
  12. int mult;
  13. int main()
  14. {
  15. stack s;
  16. s.top=-1;
  17. int i,len;
  18. char temp[101],c;
  19. gets(temp);
  20. len=strlen(temp);
  21. i=0;
  22. while(i<len)
  23. {
  24. c=temp[i];
  25. if(c!=')')
  26. {
  27. switch(c)
  28. {
  29. case 'H':
  30. push(&s,1);
  31. break;
  32. case 'O':
  33.  
  34. push(&s,16);
  35. break;
  36. case 'C':
  37.  
  38. push(&s,12);
  39. break;
  40. case '(':
  41. push(&s,0);
  42. break;
  43.  
  44. default : mult=c-'0';
  45. int q=s.a[s.top];
  46. q=q*mult;
  47. s.top--;
  48. push(&s,q);
  49. break;
  50. }
  51. }
  52. else // ) pop
  53. {
  54. pop(&s);
  55. if(i+1<len && isdigit(temp[i+1]))
  56. {
  57. int val,mult;
  58. mult=temp[i+1]-'0';
  59. val=s.a[s.top];
  60. val=val*mult;
  61. s.top--;
  62. push(&s,val);
  63. i++;
  64. }
  65.  
  66. }
  67.  
  68. i++;
  69. }
  70. int sum=0;
  71. while(s.top!=-1)
  72. {
  73. sum+=s.a[s.top];
  74. s.top--;
  75. }
  76. printf("%d",sum);
  77. return 0;
  78. }
  79. void push(stack *s,int val)
  80. {
  81. s->a[++s->top]=val;
  82. }
  83. void pop(stack *s)
  84. {
  85. int v,t=0;
  86. while(s->a[s->top]!=0)
  87. {
  88. v=s->a[s->top--];
  89. t+=v;
  90. }
  91. s->top--;
  92. push(s,t);
  93. }
  94.  
Success #stdin #stdout 0s 4308KB
stdin
Standard input is empty
stdout
Standard output is empty