Go: package main

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

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>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int calc_score(vector<int> pins)
{
	int score = 0;
	int frame = 1;
	int frame_cnt = 1;
	int now = 0;

	rep(i,pins.size())
	{
		if (frame != 10)
		{
			if (frame_cnt == 1)
			{
				if (pins[i] == 10)
				{
					//????????¬????????????????????§??????????????????????????????
					score += 10;
					for (int j=i+1; j<=i+2 && j<pins.size(); j++)
						score += pins[j];
					frame++;
					frame_cnt = 1;	
					continue;
				} else {
					score += pins[i];
					frame_cnt++;
					continue;
				}
			} else if (frame_cnt == 2) {
				if (pins[i-1] + pins[i] == 10)
				{
					//????????¢???????????????
					score += pins[i];
					score += pins[i+1];
					frame++;
					frame_cnt = 1;
					continue;
				} else {
					score += pins[i];
					frame++;
					frame_cnt = 1;
					continue;
				}
			}
		} else if (frame == 10) {
			if (frame_cnt == 1)
			{
				if (pins[i] == 10)
				{
					score += 10;
					//for (int j=i+1; j<=i+2 && j<pins.size(); j++)
					//	score += pins[j];
					frame_cnt = 2;
					continue;
				} else {
					score += pins[i];
					frame_cnt = 2;
					continue;
				}
			} else if (frame_cnt == 2) {
				if (pins[i-1] == 10 && pins[i] == 10)
				{
					score += 10;
					//for (int j=i+1; j<=i+2 && j<pins.size(); j++)
					//	score += pins[j];
					frame_cnt = 3;
					continue;
				} else if (pins[i-1] + pins[i] == 10) {
					score += pins[i];
					//score += pins[i+1];
					frame_cnt = 3;
					continue;
				} else {
					score += pins[i];
					continue;
				}
			} else if (frame_cnt == 3) {
				score += pins[i];
			}
		}
	}

	return score;
}

int m;
vector<int> ps;
pair<int, int> lst[100];

signed main()
{
	while (true)
	{
		cin >> m;
		if (m == 0) break;
		cin.ignore();
		string str;
		rep(i,m)
		{
			int num;
			ps.clear();

			getline(cin, str);
			//cout << "getline = " << str << endl;
			stringstream ss(str);

			ss >> num;
			//printf("num = %d\n", num);
			for (int x; ss >> x;)
			{
				ps.push_back(x);
			}

			lst[i] = make_pair(-calc_score(ps), num);
			sort(lst, lst + m);
		}

		rep(i,m)
		{
			cout << lst[i].second << " " << -lst[i].first << endl;
		}
	}
}

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) {
		return score() < that.score();
	}
	int score() {
		int ret = 0;
		int gs[10] = {};
		rep(i, 0, 10) {
			gs[i] = accumulate(all(g[i]), 0);
			ret += gs[i];
		}
		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]));
			dump(id);
			dumpc(v3);
			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;
}