Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("text.in");
- ofstream fout("text.out");
- int main() {
- string s;
- fin >> s;
- int n_rounds = 0, p = 0;
- while(isdigit(s[p]))
- n_rounds = n_rounds * 10 + (s[p++] - '0');
- ++p;
- int N = s.size();
- vector < pair < int , int > > throws;
- for(int i = p; i < N; ++i) {
- int j = i, throw1 = 0, throw2 = 0;
- while(isdigit(s[j]))
- throw1 = throw1 * 10 + (s[j++] - '0');
- if(throw1 == 10) {
- throws.emplace_back(throw1, 0);
- i = j;
- continue;
- }
- ++j;
- if(j < N)
- while(isdigit(s[j]))
- throw2 = throw2 * 10 + (s[j++] - '0');
- throws.emplace_back(throw1, throw2);
- i = j;
- }
- int sum = 0, M = throws.size(), up = min(M - 1, n_rounds - 1);
- for(int i = 0; i <= up; ++i) {
- int t1 = throws[i].first, t2 = throws[i].second;
- sum += t1 + t2;
- if(t1 == 10) {
- if(i < M - 1)
- sum += throws[i + 1].first + throws[i + 1].second;
- if(throws[i + 1].second == 0) {
- int Next = 0;
- int j = i + 2;
- while(j < M) {
- if(throws[j].first) {
- Next = throws[j].first;
- break;
- }
- else
- if(throws[j].second) {
- Next = throws[j].second;
- break;
- }
- ++j;
- }
- sum += Next;
- }
- }
- else
- if(t1 + t2 == 10)
- sum += throws[i + 1].first;
- if(i == 0)
- fout << sum;
- else
- fout << ',' << sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment