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 <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

class student{
public:
    student(int a, int b){
        id = a;
        score = b;
    }
    int id;
    int score;

    bool operator < (const student arg) const{
        if(score == arg.score){
            return id < arg.id;
        }else{
            return score > arg.score;
        }
    }
};

int main(void){
    int n;

    while(cin >> n && n){
        vector<student> v;
        int id,tmp;
        string str;
        cin.ignore();
        for(int i=0;i<n;i++){
            getline(cin,str);
            istringstream iss(str);
            vector<int> score;
            iss >> id;
            while(iss >> tmp){
                score.push_back(tmp);
            }
            
            int sum=0;
            int fcount=0;
            int mul[score.size()];
            memset(mul, 0, sizeof(mul));
            for(int j=0;j<score.size();j++){
            	if(fcount == 9){
            		sum += (mul[j] + 1) * score[j];
                }else if(score[j] == 10){ //strike
                    if(j+1 < score.size()) mul[j+1]++;
                    if(j+2 < score.size()) mul[j+2]++;
                    sum += 10;
                    sum += mul[j] * score[j];
                    fcount++;
                }else if(j+1 < score.size()){
                    if(j+1 < score.size() && score[j] + score[j+1] == 10){ //spare?
                        if(j+2 < score.size()) mul[j+2]++;
                    }
                    sum += score[j]+score[j+1];
                    sum += score[j]*mul[j] + score[j+1] * mul[j+1];
                    j++;
                    fcount++;
                }else{
                    sum += score[j] * (mul[j] + 1);
                }
            }
            v.push_back(student(id,sum));
        }
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++){
            cout << v[i].id << " " << v[i].score << endl;
        }
    }
}

C++: #include<iostream>
#include<map>
#include<functional>
#include<cstring>
using namespace std;

int main(void){
	int n;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		multimap<int,int, greater<int> > s;
		for(int i=0;i<n;i++){
			int num,sc[10][3],sck[10],res=0;
			memset(sc,0,sizeof(sc));
			memset(sck,0,sizeof(sck));
			scanf("%d",&num);
			for(int j=0;j<10;j++){
				if(j<9)for(int k=0;k<2;k++){
					scanf("%d",&sc[j][k]);
					if(sc[j][k]==10)break;
				}
				if(j==9)for(int k=0;k<3;k++){
					scanf("%d",&sc[j][k]);
					if(k==1 && sc[j][0]+sc[j][1]<10)break;
				}
			}
			for(int j=0;j<9;j++){
				if(sc[j][0]==10){
					sck[j]=10;
					if(sc[j+1][0]==10 && j<=7)sck[j]+=10+sc[j+2][0];
					else sck[j]+=sc[j+1][0]+sc[j+1][1];
				}else if(sc[j][0]+sc[j][1]==10){
					sck[j]=10+sc[j+1][0];
				}else sck[j]=sc[j][0]+sc[j][1];
			}
			sck[9]=sc[9][0]+sc[9][1]+sc[9][2];
		//	for(int j=0;j<=9;j++)res+=sck[j],printf("%d ",sck[j]);
			//printf("\n");
			s.insert(make_pair(res,num));
		}
		multimap<int,int, greater<int> >::iterator it=s.begin();
		while(it!=s.end()){
			cout << (*it).second << " " << (*it).first << endl;
			it++;
		}
	}
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int s[10][3];

P operator+(P a, int d) {
	rep(i, d) {
		if (~s[a.first][a.second + 1])a.second++;
		else {
			a.first++; a.second = 0;
		}
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			int id; scanf("%d", &id);
			int f = 0, cnt = 0;
			while (f < 9) {
				scanf("%d", &s[f][cnt]);
				if (s[f][cnt] == 10)f++;
				else if (cnt == 1) {
					f++; cnt = 0;
				}
				else cnt++;
			}
			scanf("%d%d", &s[9][0], &s[9][1]);
			if (s[9][0] + s[9][1] >= 10)scanf("%d", &s[9][2]);
			P p(0, 0);
			while (p.first < 9) {
				if (s[p.first][p.second] == 10) {
					P a = p + 1, b = p + 2;
					s[p.first][p.second] += s[a.first][a.second] + s[b.first][b.second];
				}
				if (p.second > 0 && s[p.first][p.second - 1] + s[p.first][p.second] == 10) {
					P a = p + 1;
					s[p.first][p.second] += s[a.first][a.second];
				}
				p = p + 1;
			}
			cnt = 0;
			rep(i, 10)rep(j, 3) {
				if (~s[i][j])cnt += s[i][j];
			}
			v.push_back(P(cnt, id));
		}
		sort(v.begin(), v.end(), [](P a, P b) {
			if (a.first != b.first)return a.first > b.first;
			return a.second < b.second;
		});
		for (auto p : v) {
			printf("%d %d\n", p.second, p.first);
		}
	}
}