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 <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] = 0;
			}
		}
		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;
					}
				}
				//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 <iostream>
using namespace std;
struct score{
    int first,second,last;
};
struct status{
    score turn[11];
    int point;
    int id;
};

status flame[41];
int m;

void INPUT(int i);
void RESULT(int i);
int strike(int i,int t);
int spair(int i,int t);

int main(void){
    cin>>m;
    while(m!=0){
        for(int i=1;i<=m;i++){
            INPUT(i);
            RESULT(i);
        }
        status sub;
        for(int i=1;i<m;i++){
            for(int j=i+1;j<=m;j++){
                if(flame[i].point<flame[j].point||(flame[i].point==flame[j].point&&flame[i].id>flame[j].id)){
                    sub=flame[i];
                    flame[i]=flame[j];
                    flame[j]=sub;
                }
            }
        }
        for(int i=1;i<=m;i++){
            cout<<flame[i].id<<' '<<flame[i].point<<endl;
        }
        cin>>m;
    }
}

void INPUT(int i){
    cin>>flame[i].id;
    for(int j=1;j<=10;j++){
        flame[i].turn[j].first=0;
        flame[i].turn[j].second=0;
        flame[i].turn[j].last=0;
        if(j!=10){    
            cin>>flame[i].turn[j].first;
            if(flame[i].turn[j].first!=10){cin>>flame[i].turn[j].second;}
        }
        else{
            cin>>flame[i].turn[j].first;
            cin>>flame[i].turn[j].second;
            if(flame[i].turn[j].first+flame[i].turn[j].second>=10){
                cin>>flame[i].turn[j].last;
            }
        }
    }
}

void RESULT(int i){
    int p;
    p=0;
    for(int j=1;j<=10;j++){
        if(j!=10){
            if(flame[i].turn[j].first==10){
                p+=strike(i,j);
            }
            else if(flame[i].turn[j].first+flame[i].turn[j].second==10){
                p+=spair(i,j);
            }
            else{
                p+=flame[i].turn[j].first+flame[i].turn[j].second;
            }
        }
        else{
            p+=flame[i].turn[j].first+flame[i].turn[j].second+flame[i].turn[j].last;
        }
    }
    flame[i].point=p;
}

int spair(int i,int t){
    int p;
    p=10+flame[i].turn[t+1].first;
    return p;
}

int strike(int i,int t){
    int p;
    p=10;
    p+=flame[i].turn[t+1].first;
    if(flame[i].turn[t+1].first!=10||t==9){
        p+=flame[i].turn[t+1].second;
    }
    else{
        p+=flame[i].turn[t+2].first;
    }
    return p;
}