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<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[41],d[41][22],f[41],g,h[41],i,j,z,x;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			scanf("%d",&s[i]);
			f[i]=0;
			g=1;
			h[i]=0;
			while(1){
				scanf("%d",&d[i][f[i]]);
				h[i]+=d[i][f[i]];
				if(d[i][f[i]]==10&&g%2==1){
					g++;
				}
				g++;
				f[i]++;
				if(g==19) break;
			}
			scanf("%d %d",&d[i][f[i]],&d[i][f[i]+1]);
			h[i]+=d[i][f[i]]+d[i][f[i]+1];
			if(d[i][f[i]]+d[i][f[i]+1]>=10){
				scanf("%d",&d[i][f[i]+2]);
				h[i]+=d[i][f[i]+2];
			}
			z=0;
			for(j=0;j<f[i];j++){
				if(d[i][j]==10&&z==0){
					h[i]+=d[i][j+1]+d[i][j+2];
				}
				else if(z==0) z=1;
				else if(d[i][j-1]+d[i][j]==10&&z==1){
					h[i]+=d[i][j+1];
					z=0;
				}
				else if(z==1) z=0;
			}
		}
		x=0;
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(h[i]<h[j]){
					x=h[i];
					h[i]=h[j];
					h[j]=x;
					x=s[i];
					s[i]=s[j];
					s[j]=x;
				}
				if(h[i]==h[j]){
					if(s[i]>s[j]){
						x=h[i];
						h[i]=h[j];
						h[j]=x;
						x=s[i];
						s[i]=s[j];
						s[j]=x;
					}
				}
			}
		}
		for(i=0;i<a;i++) printf("%d %d\n",s[i],h[i]);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

void input(vector<vint>& v)
{
	rep(i, 10)
	{
		int f;
		cin >> f;
		
		v[i][0] = f;
		
		// 2Úª éê
		if(f != 10 || i == 9)
		{
			int s;
			cin >> s;
			
			v[i][1] = s;
		}
	}
	
	// 10t[ÚÌÅãÌ
	if(v[9][0] + v[9][1] == 10 || v[9][1] == 10)
	{
		int l;
		cin >> l;
		
		v[9][2] = l;
	}
}

int search(vector<vint>& v, int I, int c)
{
	int res = 0;
	REP(i, I, 10) rep(k, 2)
		if(v[i][k] != -1 && 0 < c--) res += v[i][k];
	
	return res;
}

int calc(vector<vint> v)
{
	// Åã©çßÄ¢­
	// 10t[ÚÌÝÊ

	int res = v[9][0] + v[9][1] + (v[9][2] != -1 ? v[9][2] : 0);
	
	rep(i, 9)
	{
		if(v[i][0] == 10)
		{
			res += 10 + search(v, i + 1, 2);
		}
		else if(v[i][0] + v[i][1] == 10)
		{
			res += 10 + search(v, i + 1, 1);
		}
		else res += v[i][0] + v[i][1];
	}
	
	return res;
}

int pred(pint& a, pint& b)
{
	return a.first > b.first || (a.first == b.first && a.second < b.second);
}

int main()
{
    int n;
	while(cin >> n && n)
	{
		vector<pint> pnt(n);
		
		rep(i, n)
		{
			cin >> pnt[i].second;

			vector<vint> v(10, vint(3, -1));
			
			// üÍðó¯æé
			input(v);
			
			// ¾_ðvZ·é
			pnt[i].first = calc(v);
		}
		
		// å«¢Å\[g
		sort(ALL(pnt), greater<pint>());
		
		rep(i, n)
			cout << pnt[i].second << " " << pnt[i].first << endl;
	}
}

C++: #include <iostream>
#include <cstdlib>

using namespace std;

struct player{
  int id;
  int sc;
};

void func(player a[], int n)
{
  player t;

  for(int i = n-1; i >= 0; i--){
    for(int j = 1; j <= i; j++){
      if(a[j].id > a[j-1].id){
	t = a[j];
	a[j] = a[j-1];
	a[j-1] = t;
      }
    }
  }

  for(int i = n-1; i >= 0; i--){
    for(int j = 1; j <= i; j++){
      if(a[j].sc > a[j-1].sc){
	t = a[j];
	a[j] = a[j-1];
	a[j-1] = t;
      }
    }
  }

  return ;
}


int main(int argc, char **argv)
{
  int n, s, t, u, *a;
  player pl[40];

  while(1){
    cin >> n;
    if(n == 0){
      break;
    }
    for(int j = 0; j < n; j++){
      cin >> pl[j].id;

      a = (int *)calloc(10, sizeof(int));
      pl[j].sc = 0;
      for(int i = 0; i < 9; i++){
	cin >> s;
	for(int k = 0; k < i; k++){
	  if(a[k] > 0){
	    a[k]--;
	    pl[j].sc += s;
	  }
	}
	if(s == 10){
	  a[i] = 2;
	  t = 0;
	} else {
	  cin >> t;
	  for(int k = 0; k < i; k++){
	    if(a[k] > 0){
	      a[k]--;
	      pl[j].sc += t;
	    }
	  }
	  if(s+t == 10){
	    a[i] = 1;
	  }
	}
	pl[j].sc += (s+t);
      }
      cin >> s >> t;
      if(s+t >= 10){
	cin >> u;
      } else {
	u = 0;
      }
      pl[j].sc += (s+t+u);
      for(int k = 7; k < 9; k++){
	if(a[k] > 0){
	  a[k]--;
	    pl[j].sc += s;
	}
	if(a[k] > 0){
	  a[k]--;
	  pl[j].sc += t;
	}
      }

      free(a);
    }
    func(pl, n);
    for(int i = 0; i < n; i++){
      cout << pl[i].id << " " << pl[i].sc << endl;
    }
  }

  return 0;
}