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

C++: #include<iostream>
#include<algorithm>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  for(int d;cin>>d,d;){
    map<int,int,greater<int> > result;
    for(;d>0;d--){
      int name,score=0;
      cin>>name;
      int a,b;
      bool spare=false,strike=false,dbl=false;
      for(int i=0;i<10;i++){
	cin>>a;
	score+=a;
	if(dbl) score+=a,dbl=false;
	if(strike) score+=a;
	if(spare) score+=a,spare=false;
	if(a==10){
	  if(strike)dbl = true;
	  strike = true;
	}
	else{
	  cin>>b;
	  score+=b;
	  if(strike)score+=b,strike=false;
	  if(a+b==10)spare = true;
	}
      }
      if(strike){
	cin>>a>>b;
	if(dbl)score+=a;
	score+=a+b;
      }
      if(spare){
	cin>>a;
	score+=a;
      }
      result.insert(mp(score,name));
    }
    map<int, int>::iterator it = result.begin();
    while( it != result.end() ){
      cout << (*it).second << " " << (*it).first << endl;
	++it;
    }
  }
  return 0;
}