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 <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

bool exist[10000][301];

int main(){
	
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < 10000; i++){
			for(int j = 0; j < 301; j++){
				exist[i][j] = false;
			}
		}
		int id, score, round, round_small, dummy, rest;
		bool strike1, strike2, spare;
		bool last_throw;
		
		for(int loop = 0; loop < n; loop++){
			cin >> id;
			round = 1;
			round_small = 1;
			rest = 10;
			score = 0;
			strike1 = false;
			strike2 = false;
			spare = false;
			last_throw = false;
			
			while(true){
				if(round <= 9){
					cin >> dummy;
					score += dummy;
					if(strike1){
						score += dummy;
					}
					if(strike2){
						score += dummy;
					}
					if(spare){
						score += dummy;
						spare = false;
					}
					strike2 = strike1;
					strike1 = false;
					if(rest == dummy){
						if(dummy == 10){
							strike1 = true;
						}else{
							spare = true;
						}
						round++;
						round_small = 1;
						rest = 10;
					}else{
						round_small++;
						rest -= dummy;
						if(round_small >= 3){
							round_small = 1;
							round++;
							rest = 10;
						}
					}
				}else if(round == 10){
					cin >> dummy;
					score += dummy;
					if(strike1){
						score += dummy;
					}
					if(strike2){
						score += dummy;
					}
					if(spare){
						score += dummy;
						spare = false;
					}
					strike2 = strike1;
					strike1 = false;
					if(rest == dummy){
						last_throw = true;
						round_small++;
						rest = 10
					}else{
						round_small++;
						rest -= dummy;
					}
					if(round_small >= 3){
						if(last_throw){
							cin >> dummy;
							score += dummy;
						}
						break;
					}
				}
				//cout << "round_next = " << round << " : rest_next = " << rest << ", score = " << score << endl;
			}
			exist[id][score] = true;
		}
		for(int i = 300; i >= 0; i--){
			for(int j = 0; j < 10000; j++){
				if(exist[j][i]){
					cout << j << " " << i << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

struct Player {
    int point;
    int id;
    Player(int id, int point) : id(id), point(point) {}
};

bool operator<(const Player& a, const Player& p){
    return a.point == p.point ? a.id < p.id : a.point > p.point;
}
int main()
{
    int n;
    while (n = in()){
        vector<Player> players;
        rep(i, n){
            int id = in();
            bool is_frame_end = true;
            int multi[32] = {};
            int frame = 1;
            int now = 0;
            int point = 0;
            int prev = 0;
            while (frame < 10){
                int b = in();
                point += b + multi[now] * b;
                if (is_frame_end){
                    if (b == 10){
                        multi[now + 1]++;
                        multi[now + 2]++;
                        frame++;
                    }
                    else {
                        prev = b;
                        is_frame_end = false;
                    }
                }
                else {
                    if (b + prev == 10) multi[now + 1]++;
                    frame++;
                    is_frame_end = true;
                }
                now++;
            }
            int f, s, t;
            f = in();
            s = in();
            if (f + s >= 10) t = in();
            else t = 0;
            point += f + s + t;
            point += f * multi[now] + s * multi[now + 1];
            players.push_back(Player(id, point));
        }
        sort(players.begin(), players.end());

        rep(i, n){
            printf("%d %d\n", players[i].id, players[i].point);
        }
    }

    return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(void){
    // Your code here!
    while (true){
    int n,d=1,u=1,m=0,t=0,a,b;
    cin >> n;
    if (n==0) break;
    vector<int> id(n),s(n),dd(100);
    for (int i=0;i<100;i++){
        dd.at(i)=1;
    }
    for (int i=0;i<n;i++){
        cin >> id.at(i);
        t=0;u=1;m=0;d+=2;
        while (true){
            if (u<10){
            cin >> a;
            t=t+a;
            if (m==0 && t<10) {m++;d++;continue;}
            else if (t<10) {s.at(i)+=(t-a)*dd.at(d-1);s.at(i)+=a*dd.at(d);d++;t=0;u++;m=0;}
            else if (m==0 && t==10) {s.at(i)+=t*dd.at(d);dd.at(d+1)++;dd.at(d+2)++;t=0;u++;m=0;d++;}
            else {s.at(i)+=(t-a)*dd.at(d-1);s.at(i)+=a*dd.at(d);dd.at(d+1)++;t=0;u++;m=0;d++;}
            }
            if (u==10){
                cin >> a >> b;
                if (a+b>=10) {s.at(i)+=a*dd.at(d);s.at(i)+=b*dd.at(d+1);cin >> a;s.at(i)+=a;}
                else {s.at(i)+=a*dd.at(d);s.at(i)+=b*dd.at(d);}
                break;
            }
        }
    }
    vector<pair<int,int>> v(n);
    for (int i=0;i<n;i++){
        v.at(i).second=s.at(i);
        v.at(i).first=id.at(i);
    }
    sort(v.begin(),v.end(), [&](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;
		});
    for (int i=0;i<n;i++) {
			cout << v[i].first << " " << v[i].second << endl;
		}
}
}