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 "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

class Player {
public:
	int id;
	vector<int> g[10];
	vector<int> idx[10];
	vector<int> s;
	int h[10] = {};
	Player(int id, vector<int> s) :id(id), s(s) {
		int game = 0;
		int cnt = 0;
		rep(i, 0, s.size()) {
			assert(game < 10);
			if (cnt == 0) {
				g[game].emplace_back(s[i]);
				idx[game].emplace_back(i);
				if (s[i] == 10) {
					if (game == 9) {
						g[game].emplace_back(s[i + 1]);
						g[game].emplace_back(s[i + 2]);
						idx[game].emplace_back(i + 1);
						idx[game].emplace_back(i + 2);
						break;
					}
					h[game] = 2;
					game++;
				}
				else cnt++;
			}
			else if (cnt == 1) {
				g[game].emplace_back(s[i]);
				idx[game].emplace_back(i);
				if (s[i] + s[i - 1] == 10) {
					if (game == 9) {
						g[game].emplace_back(s[i + 1]);
						idx[game].emplace_back(i + 1);
						break;
					}
					h[game] = 1;
				}
				game++;
				cnt = 0;
			}
		}
	}
	bool operator<(Player that) {
		int a = score(), b = that.score();
		return a == b ? id > that.id:a < b;
	}
	int score() {
		int ret = 0;
		int gs[10] = {};
		rep(i, 0, 10) {
			gs[i] = accumulate(all(g[i]), 0);
			ret += gs[i];
		}
		dump(ret);
		rep(i, 0, 10) {
			if (h[i] >= 1)ret += s[idx[i + 1][0]];
			if (h[i] == 2)ret += s[idx[i + 1][0] + 1];
		}
		dump(ret);
		return ret;
	}
};

//delimiter??£?¶?????????????delimiter?????????
vector<string> split(const string& input, const char& delimiter) {
	vector<string> ret;
	string w;
	for (const char& c : input) {
		if (c == delimiter) {
			if (w.size())	ret.emplace_back(w);
			w.clear();
		}
		else w += c;
	}
	if (w.size())	ret.emplace_back(w);
	return ret;
}

signed main() {
	for (int m; cin >> m&&m;) {
		vector<Player> v;
		cin.ignore();
		rep(i, 0, m) {
			string s;
			getline(cin, s);
			vector<string> v2 = split(s, ' ');
			int id = stoi(v2[0]);
			vector<int> v3;
			rep(j, 1, v2.size())v3.emplace_back(stoi(v2[j]));
			v.emplace_back(id, v3);

			rep(k, 0, 10) {
				dumpc(v[i].g[k]);
			}
			dumpc(v[i].h);
		}
		sort(all(v));
		rrep(i, 0, v.size()) {
			cout << v[i].id << " " << v[i].score() << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

#define MAX_N 300000

int game[MAX_N][10], x[MAX_N][10][3];
int score[MAX_N][10];
int sum[MAX_N], cust[MAX_N];
int n, cnt, sum2;

pair<int, int>bowling[MAX_N];

int main() {
	while (true) {
		//memset.
		memset(game, 0, sizeof(game));
		memset(x, 0, sizeof(x));
		memset(score, 0, sizeof(score));
		memset(sum, 0, sizeof(sum));
		memset(cust, 0, sizeof(cust));
		memset(bowling, 0, sizeof(bowling));

		cin >> n;
		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			cin >> cust[i];

			for (int j = 0; j < 10; j++) {
				//cin.
				cnt = 0;
				while (true) {
					cin >> x[i][j][cnt];

					//1-9 Frame.
					if (j < 9) {
						if (x[i][j][cnt] == 10) {
							goto Exit;
						}
						if (cnt == 1) {
							goto Exit;
						}
					}

					//10 Frame.
					else {
						if (cnt == 1) {
							if (x[i][j][0] != 10 && x[i][j][0] + x[i][j][1] != 10) {
								goto Exit;
							}
						}
						else if (cnt == 2) {
							goto Exit;
						}
					}

					//End Throw.
					cnt++;
				}
			Exit:;
				game[i][j] = cnt + 1;
			}
		}
		
		//check.
		for (int i = 0; i < n; i++) {

			//sum.
			for (int j = 0; j < 10; j++) {
				sum2 = 0;
				for (int k = 0; k < game[i][j]; k++) {
					sum2 += x[i][j][k];
				}

				//1-9 Frame.
				if (j < 9) {
					//Normal.
					if (sum2 < 10) {
						score[i][j] = sum2;
					}

					//Spair.
					else if (game[i][j] == 2) {
						score[i][j] = 10 + x[i][j + 1][0];
					}

					//Strike!!
					else {
						if (game[i][j + 1] == 1) {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 2][0];
						}
						else {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 1][1];
						}
					}
				}

				//10 Frame.
				else {
					score[i][j] = sum2;
				}
			}

			//Calc.
			for (int j = 0; j < 10; j++) {
				sum[i] += score[i][j];
			}
		}

		//pair-input.
		for (int i = 0; i < n; i++) {
			bowling[i] = make_pair(sum[i], cust[i]);
		}

		//sort.
		sort(bowling, bowling + n, greater<pair<int, int> >());

		//print.
		for (int i = 0; i < n; i++) {
			cout << bowling[i].second << ' ' << bowling[i].first << endl;
		}
	}
	return 0;
}