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++: // 2011/02/27 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct player{
	int num;
	int sco;
};

int main()
{
	while(true){
		string str;
		getline(cin, str);
		istringstream ist(str);
		int m;
		ist >> m;
		if(m==0)
			break;

		struct player ply[40];
		for(int i=0; i<m; i++){
			getline(cin, str);
			istringstream ist2(str);

			ist2 >> ply[i].num;
			int pin[21];
			for(int j=0; ist2 >> pin[j]; j++)
				;

			ply[i].sco = 0;
			int k = 0;
			for(int j=1; j<=9; j++){
				ply[i].sco += pin[k++];
				if(pin[k-1]==10){
					ply[i].sco += (pin[k]+pin[k+1]);
					continue;
				}
				ply[i].sco += pin[k++];
				if(pin[k-2]+pin[k-1]==10){
					ply[i].sco += pin[k];
					continue;
				}
			}
			ply[i].sco += pin[k++];
			ply[i].sco += pin[k++];
			if(pin[k-2]==10||pin[k-2]+pin[k-1]==10)
				ply[i].sco += pin[k];

		}

		for(int i=0; i<m-1; i++)
			for(int j=i+1; j<m; j++)
				if(ply[i].sco<ply[j].sco){
					struct player tmp = ply[i];
					ply[i] = ply[j];
					ply[j] = tmp;
				}

		for(int i=0; i<m; i++)
			cout << ply[i].num << ' ' << ply[i].sco << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
class Mem{
  public:
  int name;
  int point;
  
  bool operator <(const Mem& b) const
  {
    if(point>b.point) return true;
    if(point<b.point) return false;
    if(name<b.name) return true;
    return false;
  };
  
};
int main(void){ 
  int n;
  while(cin>>n){
    if(!n) break;
    Mem m[40];
    REP(i,n){
      cin>>m[i].name;
      int p[10][3]={0};
      REP(j,9){
        cin>>p[j][0];
        if(p[j][0]!=10)
          cin>>p[j][1];
      }
      cin>>p[9][0];
      cin>>p[9][1];
      if(p[9][0]+p[9][1]>=10) cin>>p[9][2];
      m[i].point = 0;
      REP(j,9){
        REP(k,2)
          m[i].point += p[j][k];
        if(p[j][0]==10){
          m[i].point += p[j+1][0];
          if(j!=8&&p[j+1][0]==10)
            m[i].point+=p[j+2][0];
          else
            m[i].point+=p[j+1][1];
        }
        else if(p[j][0]+p[j][1]==10){
          m[i].point+=p[j+1][0];
        }
      }
      m[i].point+=p[9][0]+p[9][1]+p[9][2];
    }
    sort(m,m+n);
    REP(i,n){
      cout << m[i].name << " " <<m[i].point << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
using namespace std;

unordered_map<int, int>U;
vector<int>r;
vector<int>bunkatu(string a) {
	a += " ";
	vector<int>V;
	string b;
	for (char c : a) {
		if (c == ' ') { V.push_back(stoi(b)); b = ""; }
		else b += c;
	}
	return V;
}
int main(){
	int a;
	while (cin >> a, a) {
		U.clear();
		r.clear();
		for (int l = 0; l < a; l++) {
			int n; cin >> n;
			r.push_back(n);
			string b; getline(cin, b);
			b = b.substr(1, b.length() - 1);
			vector<int>V = bunkatu(b);
			int now = 0;
			int sum = 0;
			for (int i = 0; i < 10; i++) {
				if (V[now] == 10) {
					sum += 10 + V[now+1] + V[now+2];
					now++;
					continue;
				}
				int k = V[now] + V[now + 1];
				if (k == 10)k += V[now + 2];
				sum += k;
				now += 2;
			}
			U[n] = sum;
		}
		sort(r.begin(),r.end(), [](int a, int b) {if (U[a] != U[b])return U[a] > U[b]; return a < b; });
		for (int i = 0; i < a; i++) {
			cout << r[i] << " " << U[r[i]] << endl;
		}
	}
}