Advertisement
Emiliatan

1016

Jul 1st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. /* 1016 . B.Baseball Game */
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. string s;
  8. bool base[4], is_red_attack;
  9. int blue_goal, red_goal, out;
  10.  
  11. inline void get_goal()
  12. {
  13.     if(is_red_attack) red_goal++;
  14.     else blue_goal++;
  15. }
  16. inline void Walk()
  17. {
  18.     if(base[1])
  19.         if(base[2])
  20.             if(base[3]) get_goal();
  21.             else base[3] = true;
  22.         else base[2] = true;
  23.     else base[1] = true;
  24. }
  25. inline void hit(int kind)
  26. {
  27.     for(int i = 3; i >= 1; --i)
  28.         if(base[i])
  29.             if(i + kind >= 4)
  30.             {
  31.                 base[i] = false;
  32.                 get_goal();
  33.             }
  34.             else base[i + kind] = true, base[i] = false;
  35.     base[kind] = true;
  36. }
  37. inline void base_clear()
  38. {
  39.     base[1] = base[2] = base[3] = false;
  40. }
  41. int main()
  42. {
  43.     ios_base::sync_with_stdio(false);
  44.     cin.tie(0), cout.tie(0);
  45.     while(getline(cin, s, '\n') && !s.empty())
  46.     {
  47.         is_red_attack = true;
  48.         blue_goal = red_goal = out = 0;
  49.         base_clear();
  50.         for(auto now : s)
  51.         {
  52.             if(now == 'K' || now == 'O') ++out;
  53.             else if(now == 'W') Walk();
  54.             else if(now == 'S') hit(1);
  55.             else if(now == 'D') hit(2);
  56.             else if(now == 'T') hit(3);
  57.             else if(now == 'H')
  58.             {
  59.                 for(auto player : base)
  60.                     if(player) get_goal();
  61.                 base_clear();
  62.                 get_goal();
  63.             }
  64.             if(out == 3){ is_red_attack = !is_red_attack, out = 0; base_clear(); }
  65.         }
  66.         cout << red_goal << ' ' << blue_goal << '\n';
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement