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

using namespace std;

typedef pair<int,int> P;

vector<int> Point(string s){
  stringstream ss(s);
  int num;
  vector<int> v;

  while(ss >> num){
    v.push_back(num);
  }

  return v;
}

int getScore(string s){
  vector<int> a;
  a = Point(s);
  int len = (int)a.size();
  int score = 0 , sum = 0;
  int p = 0,n = 0;

  for(int i = 0 ; i < len ; i++){
    if(p >= 9){
      p++;
      score += a[i];
    }else{
      if(a[i] == 10 && n == 0){
	score += a[i] + a[i+1] + a[i+2];
	p++;
      }else{
	n++;
	sum += a[i];
	if(n == 2){
	  n = 0;
	  score += sum;
	  if(sum == 10){
	    score += a[i+1];
	  }
	  p++;
	  sum = 0;
	}
      }
    }
  }

  return -score;
}

int main(){
  int m;
  while(cin >> m ,m){
    vector<P> v;
    string pin;
    for(int i = 0 ; i < m ; i++){
      int score,num;
      cin >> num;

      getline(cin,pin);
      score = getScore(pin);
  
      v.push_back(P(score,num));
    }
    sort(v.begin(),v.end());
    for(int i = 0 ; i < m ; i++){
      cout << v[i].second << " " << -v[i].first << endl;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  for(int d;cin>>d,d;){
    vector<pair<int,int> > result;
    for(int i=0;i<d;i++){
      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.push_back(mp(-score,name));
    }
    sort(result.begin(),result.end());
    for(int i=0;i<d;i++){
      cout<<result[i].second<<" "<<-result[i].first<<endl;
    }
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

struct game{
	int i;
	vector<int> point;
	game() : i(0){}
	game(int i) : i(i){}
	bool strike(){ return point[0] == 10;}
	bool spare(){ return point[0] + point[1] == 10;}
	bool fill(){ return strike() || sz(point) == 2;}
	int sum(){ return accumulate(point.begin(),point.end(),0); }
};

bool CMP(const Pii& l,const Pii &r){ return l.second == r.second ? l.first < r.first : l.second > r.second; }

int main(){
	int n;
	while(cin>>n,n){
		vector<Pii> out;
		FOR(i,n){
			int id; cin>>id;
			string line; getline(cin,line);
			istringstream iss(line);
			vector<game> g(1);
			vector<int> v;
			int a; 
			while(iss>>a){
				v.push_back(a);
				g.back().point.push_back(a);
				if(sz(g) != 10 && g.back().fill())
					g.push_back(game(sz(v)));
			}

			int ans = 0;
			FOR(i,9){
				ans += g[i].sum();
				if(g[i].strike()){
					int c = g[i].i;
					ans += v[c+1] + v[c+2];
				} else if(g[i].spare()){
					ans += v[g[i].i+2];
				}
			}
			ans += g[9].sum();
			out.push_back(Pii(id,ans));
		}
		sort(out.begin(),out.end(),CMP);
		FOR(i,sz(out)){
			printf("%d %d\n",out[i].first,out[i].second);
		}
	}


	return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<int, int> P;
 
vector<int> Point(string s)
{
    stringstream ss(s);
    int num;
    vector<int> v;
 
    while (ss >> num) {
	v.push_back(num);
    }
    return v;
}
 
int getScore(string s)
{
    vector<int> a;
    a = Point(s);
    int len = (int)a.size();
    int score = 0 , sum = 0;
    int p = 0, n = 0;
 
    for (int i = 0; i < len; i++) {
	if (p >= 9) {
	    p++;
	    score += a[i];
	} else {
	    if (a[i] == 10 && n == 0) {
		score += a[i] + a[i+1] + a[i+2];
		p++;
	    } else {
		n++;
		sum += a[i];
		if (n == 2) {
		    n = 0;
		    score += sum;
		    if (sum == 10) {
			score += a[i+1];
		    }
		    p++;
		    sum = 0;
		}
	    }
	}
    }
 
    return -score;
}
 
int main()
{
    int m;
    while (cin >> m, m) {
	vector<P> v;
	string pin;
	for (int i = 0; i < m; i++) {
	    int score, num;
	    cin >> num;
 
	    getline(cin, pin);
	    score = getScore(pin);
   
	    v.push_back(P(score, num));
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < m; i++) {
	    cout << v[i].second << " " << -v[i].first << endl;
	}
    }
    return 0;
}