fork download
  1. /*
  2.   Author: Nguyen Nhut Truong
  3.   From Chuyen Tien Giang High School For The Gifted
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. //#define int long long
  9. #define start signed main
  10. #define fi first
  11. #define se second
  12. #define pb push_back
  13. #define eb emplace_back
  14. #define il pair<int,ll>
  15. #define ii pair<int,int>
  16. #define len(s) (int)s.size()
  17. #define all(s) (s).begin(),(s).end()
  18. #define OpenFile(Name) if (fopen(Name".inp","r")) freopen(Name".inp","r",stdin),freopen(Name".out","w",stdout);
  19.  
  20. #define MASK(x) ((1LL)<<(x))
  21. #define Bit(x,i) (((x)>>(i))&1)
  22. #define Countbit(x) __builtin_popcountll(x)
  23.  
  24. typedef long long ll;
  25. typedef long double ld;
  26.  
  27. int dx[]={1,-1,0,0,-1,1,1,-1};
  28. int dy[]={0,0,1,-1,-1,-1,1,1};
  29.  
  30. template <class C> bool Minimize(C &a, C b) { if (a>b) { a=b; return true; } return false;}
  31. template <class C> bool Maximize(C &a, C b) { if (a<b) { a=b; return true; } return false;}
  32.  
  33. inline ll add(ll a,ll b,ll c) { return (a+b)%c; };
  34. inline ll suf(ll a,ll b,ll c) { return (a-b+c)%c; };
  35. inline ll mul(ll a,ll b,ll c) { return ((a%c)*(b%c))%c; };
  36.  
  37. mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
  38.  
  39. ll rand(ll l,ll r){
  40. assert(l<=r);
  41. return l+rd()%(r-l+1);
  42. }
  43.  
  44. void MakeInp() {
  45. ofstream cout("Task.inp");
  46.  
  47. cout.close();
  48. }
  49.  
  50. /// Constant Limit
  51.  
  52. const int N=1e6+5,M=1e3+5,INF=1e9,lim=1e6;
  53. const int block=448,base=31;
  54.  
  55. ll Mod=1e9+7,Mod_base=1777777777,LNF=1e18;
  56.  
  57. ///________________________________________________________________________________________________________
  58.  
  59.  
  60. stack<int> a;
  61.  
  62. start() {
  63. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  64. OpenFile("TASK");
  65.  
  66. string s; getline(cin,s);
  67.  
  68. ll k=0,cur=0;
  69.  
  70. for (int i=0;i<len(s);++i) {
  71. if (s[i]=='H') a.push(1); else
  72. if (s[i]=='C') a.push(12); else
  73. if (s[i]=='O') a.push(16); else
  74. if (s[i]=='(') a.push(-1); else
  75. if (s[i]>='0' && s[i]<='9') {
  76. k=a.top();
  77. a.pop();
  78. a.push(k*(s[i]-'0'));
  79. }
  80. if (s[i]==')') {
  81. cur=0;
  82. while (!a.empty() && a.top()!=-1) {
  83. cur+=a.top();
  84. a.pop();
  85. }
  86. a.pop();
  87. a.push(cur);
  88. }
  89. }
  90.  
  91. ll ans=0;
  92. while (!a.empty()) {
  93. ans+=a.top();
  94. a.pop();
  95. }
  96.  
  97. cout<<ans;
  98.  
  99.  
  100.  
  101.  
  102. //cerr<<"\nBien dich thanh cong\nTime: "<<(1.0*clock()/CLOCKS_PER_SEC)<<" s\n";
  103. return 0;
  104. }
  105.  
  106.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty