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>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int s[30][5];

P operator+(P a, int d) {
	rep(i, d) {
		if (!~s[a.first][a.second + 1]) {
			a.first++; a.second = 0;
		}
		else a.second++;
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d%*c", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			string S; getline(cin, S);
			stringstream buf(S);
			int id; buf >> id;
			int f = 1; bool b = 0;
			while (f <= 9) {
				buf >> s[f][b];
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			buf >> s[10][0] >> s[10][1];
			if (s[10][0] == 10 || s[10][1] == 10 || s[10][0] + s[10][1] == 10)buf >> s[10][2];
			int k;
			if (buf >> k)s[10][2] = k;
			P p(1, 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&& 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;
			}
			int cnt = 0;
			for (int i = 1; i <= 10; i++)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);
		}
	}
}

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

typedef pair<int,int> P;

int main(){
	int n;
	while(cin >> n,n){
		int id;
		vector<P> vec;
		for(int ii = 0;ii < n;ii++){
			int add[21] = {},score[21] = {},sum = 0,frame = 0,tou = 1;
			cin >> id;
			for(int i = 0;frame < 10;i++){
				cin >> score[i];
				//cout << score[i] << " " << frame << " " << tou << endl;
				add[i]++;
				if(tou == 1 && score[i] == 10){
					if(frame != 9){
						frame++;
						add[i + 1]++;
						add[i + 2]++;
					}else{
						if(tou == 3) frame++;
						tou++;
					}
				}else if(tou == 2 && score[i] + score[i - 1] == 10){
					if(frame == 9) tou = 3;
					else{
						frame++;
						add[i + 1]++;
						tou = 1;
					}
				}else if(tou == 2){
					frame++;
					tou = 1;
				}else if(tou == 3) frame++;
				else tou++;
			}
			for(int i = 0;i < 21;i++){
				sum += score[i] * add[i];
			}
			vec.push_back(P(sum,-id));
		}
		sort(vec.begin(),vec.end(),greater<P>());
		for(int i = 0;i < n;i++){
			cout << -vec[i].second << " " << vec[i].first << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

pii score(){
    int id,in;
    cin >> id;
    vp v;
    //first:ピンの数、second:0無,1スペア,2ストライク
    rep(i,9){
        int sum = 0;
        cin >> in;
        if(in == 10){//ストライク
            v.push_back(pii(in,2));
        }else{
            sum += in;
            cin >> in;
            v.push_back(pii(sum,0));
            v.push_back(pii(in,sum+in == 10));
        }
    }
    int sum = 0;
    cin >> in;
    sum += in;
    v.push_back(pii(in,0));
    cin >> in;
    sum += in;
    v.push_back(pii(in,0));
    if(sum >= 10){
        cin >> in;
        sum += in;
        v.push_back(pii(in,0));
    }

    int ret = 0;
    rep(i,v.size()){
        ret += v[i].first;
        if(v[i].second >= 1 && i+1 < v.size()){
            ret += v[i+1].first;
        }
        if(v[i].second == 2 && i+2 < v.size()){
            ret += v[i+2].first;
        }
    }
    //cout << "!" << ret << " " << id << endl;
    return pii(-ret, id);
}


signed main(void) {
    int m;
    while(cin >> m, m){
        vp v;
        rep(i,m)v.push_back(score());
        sort(all(v));
        rep(i,m){
            cout << v[i].second << " " << -v[i].first << endl;
        }

    }
}

C++: #include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
bool desc(pair<int, int> a, pair<int, int> b) {
	if(a.second != b.second) return a.second > b.second;
	else return a.first < b.first;
}
int main() {
	int n, a;
	while(cin >> n, n) {
		vector<pair<int,int> > v;
		rep(i,n) {
			cin >> a;
			int s[10][2] = {}, cnt = 0, b, c, score = 0;
			while(cnt < 9) {
				cin >> b;
				if(b == 10) {
					s[cnt][0] = 10;
					cnt++;
					continue;
				}
				cin >> c;
				s[cnt][0] = b;
				s[cnt][1] = c;
				cnt++;
			}
			cin >> b >> c;
			s[cnt][0] = b;
			s[cnt][1] = c;
			if(b + c >= 10) cin >> score;
			rep(i,9) {
				if(s[i][0] == 10) {
					s[i][0]+=s[i+1][0];
					if(s[i+1][0] == 10 && i != 8) s[i][0] += s[i+2][0];
					else s[i][0] += s[i+1][1];
				} else if(s[i][0] + s[i][1] == 10) s[i][0] += s[i+1][0];
			}
			rep(i,10) {
				rep(j,2) {
					score += s[i][j];
				}
			}
			v.push_back(make_pair(a, score));
		}
		sort(v.begin(), v.end(), desc);
		rep(i,n) {
			cout << v[i].first << " " << v[i].second << endl;
		}
	}
	return 0;
}