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<iostream>
#include<cstring>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

#define MAX_N 50

int game[MAX_N][12], x[MAX_N][12][10];
int score[MAX_N][12];
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;
}

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

struct Player {
	int id;
	int score;
	Player() {}
	Player(int id, int score) : id(id), score(score) {}
};
bool operator > (const Player& p1, const Player& p2) {
	if (p1.score > p2.score) return true;
	else if (p1.score < p2.score) return false;
	else return p1.id < p2.id;
}

int getScore(int s[], int n)
{
	int* frame = new int[n];
	bool* strike = new bool[n];
	bool* spare = new bool[n];
	for (int i=0; i<n; i++) { strike[i] = false; spare[i] = false; }
	frame[0] = 0;
	int s_frame[10];
	for (int i=0; i<10; i++) s_frame[i] = 0;
	int thrownum = 0;
	for (int i=0; i<n; i++) {
		if (thrownum == 0) {
			if (s[i] == 10) {
				strike[i] = true;
				frame[i+1] = frame[i] + 1;
			}
			else {
				frame[i+1] = frame[i];
				thrownum = 1;
			}
			s_frame[frame[i]] += s[i];
			if (i>1) {
				if (strike[i-2]) s_frame[frame[i-2]] += s[i];
			}
			if (i>0) {
				if (strike[i-1]) s_frame[frame[i-1]] += s[i];
				if (spare[i-1])  s_frame[frame[i-1]] += s[i];
			}
		}
		else if (thrownum == 1) {
			if (s[i-1] + s[i] == 10) {
				spare[i] = true;
			}
			if (frame[i] == 9) {
				if (spare[i] || strike[i-1] || strike[i]) {
					frame[i+1] = frame[i];
					thrownum = 2;
				}
			}
			else {
				frame[i+1] = frame[i] + 1;
				thrownum = 0;
			}
			s_frame[frame[i]] += s[i];
			if (i>1) {
				if (strike[i-2]) s_frame[frame[i-2]] += s[i];
			}
			if (i>0) {
				if (strike[i-1]) s_frame[frame[i-1]] += s[i];
				if (spare[i-1])  s_frame[frame[i-1]] += s[i];
			}
		}
		else { // thrownum == 2
			s_frame[frame[i]] += s[i];
		}
	}
	int res = 0;
	for (int i=0; i<10; i++) res += s_frame[i];
	delete[] frame;
	delete[] strike;
	delete[] spare;
	return res;
}

int main()
{
	int score[30];
	std::string input;
	std::string sn; int n;
	while (true) {
		getline(std::cin, sn); n = std::stoi(sn);
		if (n==0) break;
		Player* players = new Player[n];
		for (int i=0; i<n; i++) {
			getline(std::cin, input);
			int id;
			int offset = 0;
			int pos;
			int index = 0;
			int s;
			pos = input.find(' ', offset);
			id = std::stoi(input.substr(offset, pos-offset));
			offset = pos + 1;
			while ( (pos = input.find(' ', offset)) != std::string::npos ) {
				s = std::stoi(input.substr(offset, pos-offset));
				score[index] = s; index++;
				offset = pos + 1;
			}
			s = std::stoi(input.substr(offset));
			score[index] = s; index++;
			players[i] = Player(id, getScore(score, index));
		}
		std::sort(players, players + n, std::greater<Player>());
		for (int i=0; i<n; i++) {
			std::cout << players[i].id << " " << players[i].score << std::endl;
		}
		delete[] players;
	}
	return 0;
}