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 <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int n,num[50],score[50]={0},tmp;
	int s_max,ans_num;
	vector<int> pin;

	while(cin>>n){
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>num[i];
			score[i]=0; pin.clear();
			for(int j=0;j<9;j++){
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
				if(tmp==10) continue;
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			}

			cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			if(pin[pin.size()-2]==10 || pin[pin.size()-1]+pin[pin.size()-2]==10){
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			}


			for(int j=0,k=0;j<9;j++){
				if(pin[k]==10){
					score[i]+=pin[k+1]+pin[k+2]; k++;
				}else if(pin[k]+pin[k+1]==10){
					score[i]+=pin[k+2]; k+=2;
				}else{k+=2;}
			}

		}
		
		for(int i=0;i<n;i++){
			s_max=-1;
			for(int j=0;j<n;j++){
				if(score[j]>s_max || score[j]==s_max && num[j]<num[ans_num]){
					 s_max=score[j]; ans_num=j;
				}

			}
			cout<<num[ans_num]<<" "<<score[ans_num]<<endl;
			score[ans_num]=0;
		}
	}
	
	return 0;
}

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) {
            if (first_bowl) {
                frame[cur_frame].first = 10;
                frame[cur_frame].second = -1; // 投球がなかったことのフラグ
                cur_frame++;
                bonus_spare++;
                bonus_strike++;
                first_bowl = true;
            } else {
                frame[cur_frame].second = 10;
                cur_frame++;
                bonus_spare++;
                first_bowl = true;
            }
            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 <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

enum{NONE,STRIKE,SPARE};

bool compare(pii a,pii b)
{
	return a.second==b.second?a.first<b.first:a.second>b.second;
}

int main()
{
	for(int m;cin>>m,m;){
		vector<pii> res;
		rep(i,m){
			int n; cin>>n;
			int score=0;
			int flg[2]={};
			rep(j,10){
				int p[3];
				if(j==9){
					rep(k,3){
						cin>>p[k];
						score+=p[k];
						if(flg[0]==STRIKE) score+=p[k];
						if(flg[1]) score+=p[k];
						flg[0]=flg[1];
						flg[1]=NONE;
						if(k==1 && p[0]+p[1]<10)
							break;
					}
				}
				else{
					int p[2];
					rep(k,2){
						cin>>p[k];
						score+=p[k];
						if(flg[0]==STRIKE) score+=p[k];
						if(flg[1]) score+=p[k];
						flg[0]=flg[1];
						if(p[k]==10){
							flg[1]=STRIKE;
							break;
						}
						else if(k==1 && p[0]+p[1]==10)
							flg[1]=SPARE;
						else
							flg[1]=NONE;
					}
				}
			}
			res.push_back(mp(n,score));
		}
		sort(allof(res),compare);
		rep(i,res.size())
			cout<<res[i].first<<" "<<res[i].second<<endl;
	}
	
	return 0;
}