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 <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (1) {
		int m;
		cin >> m;
		if (m == 0) break;
		vector<pair<int, int>>id(m);
		vector<vector<int>>score(m, vector<int>(10, 0));
		vector<vector<int>>eachScore(m);
		rep(i, m) {
			cin >> id[i].first;
			int num = 0;
			int point = 0;
			int cnt = 0;
			int tenNum = 0;
			while (num != 10) {
				if (num == 9) tenNum++;
				cnt++;
				int tmp;
				cin >> tmp;
				point += tmp;
				eachScore[i].push_back(tmp);

				if (tenNum == 3) {
					score[i][num] = point;
					break;
				}

				if (cnt == 2) {
					if (num == 9 && point >= 10) {
						continue;
					}
					score[i][num] = point;
					//cout << num << "番目に" << point << "はいる" << endl;
					cnt = 0;
					num++;
					point = 0;
				}
				else if (point == 10) {
					if (num == 9) continue;
					score[i][num] = point;
					if (cnt == 1) // ストライク
						score[i][num] += 10;
					//cout << num << "番目に" << point << "はいる" << endl;
					cnt = 0;
					num++;
					point = 0;
				}
			}
		}
		
		rep(i, m) {
			id[i].second = 0;
			int cnt = 0;
			int point = 0;
			int num = 0;
			rep(j, (int)eachScore[i].size()) {
				if (num == 9) {
					id[i].second += eachScore[i][j];
				}
				else {
					//cout << j << endl;
					point += eachScore[i][j];
					cnt++;
					if (point == 10) {
						// 10投目かどうか確かめる
						if (cnt == 1) {
							// ストライク
							for (int k = j + 1; k < (int)eachScore[i].size() && k < j + 3; k++) {
								id[i].second += eachScore[i][k]; // 次2回の投球をみる
							}
						}
						else { // スペア
							for (int k = j + 1; k < (int)eachScore[i].size() && k < j + 2; k++) {
								id[i].second += eachScore[i][k]; // 次の投球を見る
							}
						}
						id[i].second += point;
						point = 0;
						cnt = 0;
						num++;
					}
					if (cnt == 2) {
						id[i].second += point;
						cnt = 0;
						point = 0;
						num++;
					}
				}
			}
		}

		sort(allof(id), [&](const pair<int, int>& x, const pair<int, int>& y) {
			if (x.second == y.second) {
				return x.first < y.first;
			}
			return x.second > y.second;
		});
		
		rep(i, m) {
			cout << id[i].first << " " << id[i].second << endl;
		}
		/*rep(i, m) {
			cout << id[i].first << " ";
			rep(j, (int)eachScore[i].size()) {
				cout << eachScore[i][j] << " ";
			}
			cout << endl;
		}*/
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<pair<int,int> > infos;
		for(int i = 0; i < n; i++){
			int num;
			cin>>num;
			int frame=1;
			pair<int,int> scores[11];
			int sum=0;
			while(1){
				if(frame==10){
					int sc,sc2;
					cin>>sc>>sc2;
					int sc3=0;
					if(sc==10||sc+sc2>=10){
						cin>>sc3;
					}
					scores[10].first=sc;
					scores[10].second=sc2;
					sum+=sc3+sc+sc2;
					break;
				}
				else{
					int sc;
					cin>>sc;
					if(sc==10){
						scores[frame].first=sc;
						scores[frame].second=-1;
						frame++;
					}
					else{
						int sc2;
						cin>>sc2;
						scores[frame].first=sc;
						scores[frame].second=sc2;
						frame++;
					}
				}
			}
			// {[iXðÁZ
			for(int i = 1; i <= 9; i++){
				sum+=scores[i].first;
				// XgCN
				if(scores[i].first==10){
					sum+=scores[i+1].first;
					// XgCN¾Á½ê
					if(scores[i+1].first==10&&i+1!=10){
						sum+=scores[i+2].first;
					}
					else{
						sum+=scores[i+1].second;
					}
				}
				// XyA
				else if(scores[i].second!=-1&&scores[i].first+scores[i].second==10){
					sum+=scores[i].second;
					sum+=scores[i+1].first;
				}
				else{
					sum+=scores[i].second;
				}
			}
			infos.push_back(make_pair(sum,-num));
		}
		sort(infos.begin(),infos.end(),greater<pair<int,int> >());
		for(int i = 0; i < infos.size(); i++){
			cout<<-infos[i].second<<" "<<infos[i].first<<endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
#include<map>
using namespace std;

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;
	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;
			}
			U[n]= sum;
		}
		sort(r.begin(),r.end(), [=](int a, int b) {if (U[a] != U[b])return U[a] > U[b]; return a < b; });
		for (int i = 0; i < a; i++) {
			cout << r[i] << " " << U[r[i]] << endl;
		}
	}
}