Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"sort"
	"fmt"
)

var scanner= bufio.NewScanner(os.Stdin)

type entry struct {
	id, score int
}

type lessFunc func(p1, p2 *entry) bool

type multiSorter struct {
	entries []entry
	less []lessFunc
}

func (ms *multiSorter) sort(entries []entry) {
	ms.entries = entries
	sort.Sort(ms)
}

func OrderedBy(less ...lessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}

func (ms *multiSorter) Len() int {
	return len(ms.entries)
}

func (ms *multiSorter) Swap(i, j int) {
	ms.entries[i], ms.entries[j] = ms.entries[j], ms.entries[i]
}

func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.entries[i], &ms.entries[j]
	var k int
	for k = 0; k < len(ms.less)-1; k++ {
		less := ms.less[k]
		switch  {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	for scanner.Scan() {
		m, _ := strconv.Atoi(scanner.Text())
		if m == 0 {
			break
		}
		results := make([]entry, 0)
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			data := make([]int, len(buf))
			for i := range data {
				data[i], _ = strconv.Atoi(buf[i])
			}
			id, score := score(data)
			results = append(results, entry{id, score})
		}
		score_axis := func(e1, e2 *entry) bool {
			return e1.score > e2.score
		}
		id_axis := func(e1, e2 *entry) bool {
			return e1.id > e2.id
		}
		OrderedBy(score_axis, id_axis).sort(results)
		// log.Println(results)
		for _, e := range results {
			fmt.Printf("%d %d\n", e.id, e.score)
		}
	}
}

func score(input []int) (int, int) {
	id := input[0]
	data := input[1:]
	frame := 1
	scores := make([]int, 11)
	for frame <= 10 {
		if data[0] == 10 {
			scores[frame] = data[0] + data[1] + data[2]
			data = data[1:]
			frame += 1
		} else if data[0] + data[1] == 10 {
			scores[frame] = data[0] + data[1] + data[2]
			data = data[2:]
			frame += 1
		} else {
			scores[frame] = data[0] + data[1]
			data = data[2:]
			frame += 1
		}
	}
	sum := 0
	for i, v := range scores {
		if i != 0 {
			sum += v
		}
	}
	return id, sum
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef pair<int, int> P;
typedef pair<int, bool> Q;

int main()
{
	string str = "";
	while (getline (cin, str ) && str != "0" ){
		stringstream ssn (str );
		int n;
		ssn >> n;	
		vector<P> score (n);		
		for (int i = 0; i < n; i++ ){
			
			getline (cin, str );
			stringstream ss (str );
			ss >> score[i].second;
			int m;
			vector<int> p;
			while (ss >> m ){			
				p.push_back (m );
			} // end while
			int s[21] = {0};
			int size = p.size();
			int k = 0;
			for (int j = 0; j < size; j++ ){
				s[k] = p[j];
				if (p[j] == 10 ){
					if (k % 2 == 0 && k < 18 ){
						k++;
					}
				} // end if
				k++;
			} // end for

			vector <Q> g(10);
			for (int j = 0; j < 10; j++ ){
				if (j != 9 ){		
					g[j].first = s[2*j] + s[2*j+1];
					if (s[2*j] == 10 ){
						g[j].second = true;
					}// end if
				}else{
					g[j].first = s[2*j] + s[2*j+1] + s[2*j+2];
				} // end if
			} // end for
			int sum = 0;
			for (int j = 0; j < 10; j++ ){
				int pos = 0;	
				pos += g[j].first;
				if (j != 9 && g[j].first == 10 ){
					if (g[j].second ){
						pos += (g[j+1].second ? 10 + s[2*(j+2)] : s[2*(j+1)] + s[2*(j+1)+1]);
					}else{
						pos += s[2*(j+1)];
					} // end if
				} // end if
				sum += pos;
			} // end for
			score[i].first = -sum;

		} // end for
		sort (ALL (score ) );
		for (int i = 0; i < n; i++ ){
			cout << score[i].second << ' ' << -score[i].first << endl;
		} // end for
	} // end loop
		
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int s[10][5];

P operator+(P a, int d) {
	rep(i, d) {
		if (!~s[a.first][a.second + 1]) {
			a.first++; a.second = 0;
		}
		else a.second++;
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d", &m), m) {
		vector<P>v;
		rep(i, m) {
			string s; getline(cin, s);
			stringstream ss(s);
			int d, cnt = 0;
			while (ss >> d) {
				cnt++;
			}
			cout << cnt << endl;
			if (cnt == 12)abort();
			/*
			memset(s, -1, sizeof(s));
			int id; scanf("%d", &id);
			int f = 0; bool b = 0;
			while (f < 9) {
				scanf("%d", &s[f][b]);
				if (s[f][b] > 10)abort();
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			scanf("%d%d", &s[9][0], &s[9][1]);
			if (s[9][0] + s[9][1] >= 10)scanf("%d", &s[9][2]);
			P p(0, 0);
			while (p.first < 9) {
				if (s[p.first][p.second] == 10) {
					P a = p + 1, b = p + 2;
					s[p.first][p.second] += s[a.first][a.second] + s[b.first][b.second];
				}
				if (p.second&& s[p.first][p.second - 1] + s[p.first][p.second] == 10) {
					P a = p + 1;
					s[p.first][p.second] += s[a.first][a.second];
				}
				p = p + 1;
			}
			int cnt = 0;
			rep(i, 10)rep(j, 3) {
				if (~s[i][j])cnt += s[i][j];
			}
			v.push_back(P(cnt, id));*/
		}/*
		sort(v.begin(), v.end(), [](P a, P b) {
			if (a.first != b.first)return a.first > b.first;
			return a.second < b.second;
		});
		for (auto p : v) {
			printf("%d %d\n", p.second, p.first);
		}*/
	}
	puts("Hello,world!");
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;

int calc(int a[21]) {
  bool spare[21] = {false};
  bool strike[21] = {false};
  int s = 0, p = 0;
  for (int i=0; i<10; i++) {
    s += a[p];
    if (p>0 && (spare[p-1] || strike[p-1])) {
      s += a[p];
    }
    if (p>1 && strike[p-2]) {
      s += a[p];
    }
    if (a[p] == 10) {
      strike[p] = true;
      p++;
      continue;
    }
    s += a[p+1];
    if (p>0 && strike[p-1]) {
      s += a[p+1];
    }
    if (a[p] + a[p+1] == 10) {
      spare[p+1] = true;
    }
    p += 2;
  }
  if (spare[p-1]) {
    s += a[p];
  }
  if (strike[p-1]) {
    s += a[p];
    if (strike[p-2]) {
      s += a[p];
    }
    s += a[p+1];
  }
  return s;
}


int main() {
  int a[21];
  pair<int,int> s[40];
  int n, m, p, c;
  char buf[100];
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      fgets(buf, sizeof(buf), stdin);
      p = 0;
      sscanf(buf, "%d%n", &s[i].second, &c);
      p += c;
      m = 0;
      while (1) {
        if (sscanf(buf+p, "%d%n", &a[m], &c) != 1) break;
        ++m;
        p += c;
      }
      s[i].first = calc(a);
    }
    sort(s, s+n);
    for (int i=n-1; i>=0; i--) {
      printf("%d %d\n", s[i].second, s[i].first);
    }
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<math.h>
#include<queue>
#include<functional>
#define P pair<int,int>
using namespace std;

unordered_map<int, int>U;
vector<int>r;
vector<int>bunkatu(string a) {
	a += " ";
	vector<int>V;
	string b;
	for (char c : a) {
		if (c == ' ') { V.push_back(stoi(b)); b = ""; }
		else b += c;
	}
	return V;
}
int main() {
	int a;
	vector<P>R;
	while (cin >> a, a) {
		U.clear();
		r.clear();
		for (int l = 0; l < a; l++) {
			int n; cin >> n;
			r.push_back(n);
			string b; getline(cin, b);
			b = b.substr(1, b.length() - 1);
			vector<int>V = bunkatu(b);
			int now = 0;
			int sum = 0;
			for (int i = 0; i < 10; i++) {
				if (V[now] == 10) {
					sum += 10 + V[now + 1] + V[now + 2];
					now++;
					continue;
				}
				int k = V[now] + V[now + 1];
				if (k == 10)k += V[now + 2];
				sum += k;
				now += 2;
			}
			R.push_back({ -sum,n });
		}
		sort(R.begin(), R.end());
		for (P i : R) {
			cout << i.second << " " << -i.first << endl;
		}
	}
}