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<stdio.h>
#include<iostream>
using namespace std;
int main(){



int n;

while(1){
cin>>n;if(n==0)break;
int pn[45][2]={};
for(int i=0;i<n;i++){//cout<<"#"<<endl;
cin>>pn[i][0];int m=0,s=0,st,g=1;
int P[24][2]={};

for(int j=0;j<10;j++){s=0;
cin>>st;s+=st;P[g][0]=st;g++;
if(st==10){s=0;P[g-1][1]=1;
if(j==9){cin>>st;P[g][0]=st;P[g][1]=9;g++;
if(st==10){cin>>st;P[g][0]=st;P[g][1]=9;
}
}
}
else if(st!=10){
cin>>st;s+=st;P[g][0]=st;g++;P[g-1][1]=2;
if(j==9&&P[g-1][0]+P[g-2][0]==10){cin>>st;P[g][0]=st;P[g][1]=9;g++;
}
}
}
for(int j=1;j<23;j++){
if(P[j][1]!=9)pn[i][1]+=P[j][0];
if(P[j][1]==2&&P[j][0]+P[j-1][0]==10){pn[i][1]+=P[j+1][0];}//cout<<"$"<<endl;}
if(P[j][1]==1){pn[i][1]+=P[j+1][0]+P[j+2][0];}
//cout<<"$$"<<endl;}
//cout<<pn[i][1]<<endl;
}


//cout<<"*"<<endl;

}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(pn[j][1]>pn[j-1][1]){
int a1=pn[j][1];pn[j][1]=pn[j-1][1];pn[j-1][1]=a1;
int a0=pn[j][0];pn[j][0]=pn[j-1][0];pn[j-1][0]=a0;
}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(pn[j][1]==pn[j-1][1]&&pn[j][0]<pn[j-1][0]){
int a0=pn[j][0];pn[j][0]=pn[j-1][0];pn[j-1][0]=a0;
}
for(int i=0;i<n;i++)
printf("%d %d\n",pn[i][0],pn[i][1]);
}
return 0;
}

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++;
					}else{
						round_small++;
						rest -= dummy;
					}
					if(round_small >= 3){
						if(last_throw){
							cin >> dummy;
							score += dummy;
						}
						break;
					}
				}
				if(dummy > 10){
					while(true){
					}
				}
				//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<stdio.h>
#include<iostream>
using namespace std;
int main(){



int n;

while(1){
cin>>n;if(n==0)break;
int pn[45][2]={};
for(int i=0;i<n;i++){//cout<<"#"<<endl;
cin>>pn[i][0];int m=0,s=0,st,g=1;
int P[24][2]={};

for(int j=0;j<10;j++){s=0;
cin>>st;s+=st;P[g][0]=st;g++;
if(st==10){s=0;P[g-1][1]=1;
if(j==9){cin>>st;P[g][0]=st;P[g][1]=9;g++;
cin>>st;P[g][0]=st;P[g][1]=9;

}
}
else if(st!=10){
cin>>st;s+=st;P[g][0]=st;g++;P[g-1][1]=2;
if(j==9&&P[g-1][0]+P[g-2][0]==10){cin>>st;P[g][0]=st;P[g][1]=9;g++;
}
}
}
for(int j=1;j<23;j++){
if(P[j][1]!=9)pn[i][1]+=P[j][0];
if(P[j][1]==2&&P[j][0]+P[j-1][0]==10){pn[i][1]+=P[j+1][0];}//cout<<"$"<<endl;}
if(P[j][1]==1){pn[i][1]+=P[j+1][0]+P[j+2][0];}
//cout<<"$$"<<endl;}
//cout<<pn[i][1]<<endl;
}


//cout<<"*"<<endl;

}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(pn[j][1]>pn[j-1][1]){
int a1=pn[j][1];pn[j][1]=pn[j-1][1];pn[j-1][1]=a1;
int a0=pn[j][0];pn[j][0]=pn[j-1][0];pn[j-1][0]=a0;
}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(pn[j][1]==pn[j-1][1]&&pn[j][0]<pn[j-1][0]){
int a0=pn[j][0];pn[j][0]=pn[j-1][0];pn[j-1][0]=a0;
}
for(int i=0;i<n;i++)
printf("%d %d\n",pn[i][0],pn[i][1]);
}
return 0;
}