Alex_tz307

Bowling

Oct 26th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("text.in");
  6. ofstream fout("text.out");
  7.  
  8. int main() {
  9.     string s;
  10.     fin >> s;
  11.     int n_rounds = 0, p = 0;
  12.     while(isdigit(s[p]))
  13.         n_rounds = n_rounds * 10 + (s[p++] - '0');
  14.     ++p;
  15.     int N = s.size();
  16.     vector < pair < int , int > > throws;
  17.     for(int i = p; i < N; ++i) {
  18.         int j = i, throw1 = 0, throw2 = 0;
  19.         while(isdigit(s[j]))
  20.             throw1 = throw1 * 10 + (s[j++] - '0');
  21.         if(throw1 == 10) {
  22.             throws.emplace_back(throw1, 0);
  23.             i = j;
  24.             continue;
  25.         }
  26.         ++j;
  27.         if(j < N)
  28.             while(isdigit(s[j]))
  29.                 throw2 = throw2 * 10 + (s[j++] - '0');
  30.         throws.emplace_back(throw1, throw2);
  31.         i = j;
  32.     }
  33.     int sum = 0, M = throws.size(), up = min(M - 1, n_rounds - 1);
  34.     for(int i = 0; i <= up; ++i) {
  35.         int t1 = throws[i].first, t2 = throws[i].second;
  36.         sum += t1 + t2;
  37.         if(t1 == 10) {
  38.             if(i < M - 1)
  39.                 sum += throws[i + 1].first + throws[i + 1].second;
  40.             if(throws[i + 1].second == 0) {
  41.                 int Next = 0;
  42.                 int j = i + 2;
  43.                 while(j < M) {
  44.                     if(throws[j].first) {
  45.                         Next = throws[j].first;
  46.                         break;
  47.                     }
  48.                     else
  49.                         if(throws[j].second) {
  50.                             Next = throws[j].second;
  51.                             break;
  52.                         }
  53.                     ++j;
  54.                 }
  55.                 sum += Next;
  56.             }
  57.         }
  58.         else
  59.             if(t1 + t2 == 10)
  60.                 sum += throws[i + 1].first;
  61.         if(i == 0)
  62.             fout << sum;
  63.         else
  64.             fout << ',' << sum;
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment