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 <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(100000);
    for (int i=0;i<100000;i++){
        dd.at(i)=1;
    }
    for (int i=0;i<n;i++){
        cin >> id.at(i);
        t=0;u=1;m=0;d+=3;
        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;
		}
}
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <sstream>
#include <cassert>
using namespace std;

struct Score {
    int student_number;
    int score;
    Score() {
        score = 0;
    }
    bool operator>(const Score& o) const {
        return score == o.score ? student_number < o.student_number : score > o.score;
    }
};

int calc_score(istringstream& is) {
    vector< pair<int, int> > frame(12); // フレームごとの投球情報. 1-indexed

    int score = 0;

    int bonus_spare = 0;
    int bonus_strike = 0;
    int pin;
    int cur_frame = 1;
    int cur_pin = 0;
    bool first_bowl = true;
    while (is >> pin) {
        if (cur_frame != 11) score += pin;
        if (bonus_spare) {
            score += pin * bonus_spare;
            bonus_spare = bonus_strike;
            bonus_strike = 0;
        } 
//        cout << score << ' ';

        if (cur_frame == 11) {
            if (first_bowl) {
                frame[cur_frame].first = pin;
                first_bowl = false;
            } else {
                frame[cur_frame].second = pin;
            }
            continue;
        }

        if (pin == 10) {
            assert(first_bowl == true);
            frame[cur_frame].first = 10;
            frame[cur_frame].second = -1; // 投球がなかったことのフラグ
            cur_frame++;
            bonus_spare++;
            bonus_strike++;
            continue;
        } 

        if (first_bowl) {
            frame[cur_frame].first = pin;
            first_bowl = false;
        } else {
            frame[cur_frame].second = pin;
            if (frame[cur_frame].first + frame[cur_frame].second == 10) 
                bonus_spare++;
            first_bowl = true;
            cur_frame++;
        }
    }
    return score;
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        cin.ignore(1);
        vector<Score> info(n);
        for (int i = 0; i < n; i++) {
            Score score;
            string s; getline(cin, s);
            istringstream is(s);
            is >> score.student_number;
            score.score = calc_score(is);
            info[i] = score;
        }
        sort(info.begin(), info.end(), greater<Score>());
        for (int i = 0; i < info.size(); i++) {
            cout << info[i].student_number << ' ' << info[i].score << endl;
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<pair<int, int> > v;
		
		for (int i = 0; i < n; i++){
			int stNo;
			scanf("%d", &stNo);
			
			int frame = 0;
			int frameScore[10] = {0}, remain[10] = {0};
			int prev = -1;
			int ct = 0;
			while (frame < 10){
				int pin;
				scanf("%d", &pin);
				frameScore[frame] += pin;
				
				if (frame == 9){
					if (ct == 1 && frameScore[frame] < 10) frame++;
					else if (ct == 2) frame++;
					ct++;
				}
				
				for (int j = 0; j < 10; j++){
					if (remain[j]){
						frameScore[j] += pin;
						remain[j]--;
					}
				}
				
				if (frame < 9){
					if (prev + pin == 10){
						remain[frame] = 1;
						frame++;
						prev = -1;
					}
					else if (pin == 10){
						remain[frame] = 2;
						frame++;
						prev = -1;
					}
					else if (~prev){
						frame++;
						prev = -1;
					}
					else if (prev == -1) prev = pin;
				}
			}
			
			int sum = 0;
			for (int j = 0; j < 10; j++) sum += frameScore[j];
			v.push_back(make_pair(-sum, stNo));
		}
		
		sort(v.begin(), v.end());
		for (int i = 0; i < n; i++){
			printf("%d %d\n", v[i].second, -v[i].first);
		}
	}
	
	return (0);
}