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 <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;
}

C++: #include <iostream>
#include <algorithm>
#define N 40
using namespace std;

int d[N];
int p[N];
void mergeSort(int, int);
void merge(int, int, int);
int main(){
  int n;
  int ans1[N], ans2[N];
  int data[21];
  while(1){
    cin >> n;
    if(n==0) break;

    for(int i=0;i<n;i++){
      cin >> d[i];
      int size;
      char tmp;
      for(int j=0;;j++){
        scanf("%c", &tmp);
        if(tmp=='\n'){
          size=j;
          break;
        }
        scanf("%d", &data[j]);
      }
      int now=1;
      p[i]=0;
      int f=1;
      for(int count=0;count<size;count++){
        if(f==10){
          if(data[count]==10 & data[count+1]==10 && data[count+2]==10){
            p[i]+=30;
          }
          else if(data[count]==10){
            p[i]+=10+data[count+1]+data[count+2];
          }
          else if((data[count]+data[count+1]==10)){
            p[i]+=10+data[count+2];
          }
          else p[i]+=data[count]+data[count+1];
          break;
        }
        if(now==1){
          if(data[count]==10){
            p[i]+=10+data[count+1]+data[count+2];
            f++;
            continue;
          }
          else{
            p[i]+=data[count];
            now=2;
          }
        }
        else{
          p[i]+=data[count];
          if((data[count]+data[count-1])==10){
            p[i]+=data[count+1];
          }
          now=1;
          f++;
        }
      }
    }
    mergeSort(0, n);
    for(int i=0;i<n;i++){
      ans1[i]=p[n-i-1];
      ans2[i]=d[n-i-1];
    }
    for(int i=0;i<n-1;i++){
      int left, right;
      if(ans1[i]==ans1[i+1]){
        left=i;
        for(int j=i+1;;j++){
          if(j>=n){
            right=n;
            i=j-1;
            break;
          }
          if(ans1[i]!=ans1[j]){
            right=j;
            i=j-1;
            break;
          }
        }
        sort(ans2+left, ans2+right);
      }
    }
    for(int i=0;i<n;i++){
      cout << ans2[i] << ' ' << ans1[i] << endl;
    }
  }
  return 0;
}

void merge(int left, int mid, int right){
  int L[N/2+2], R[N/2+2];
  int l[N/2+2], r[N/2+2];
  int n1=mid-left;
  int n2=right-mid;
  for(int i=0;i<n1;i++){
    L[i]=p[left+i];
    l[i]=d[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=p[mid+i];
    r[i]=d[mid+i];
  }
  L[n1]=R[n2]=2147483647;
  l[n1]=r[n2]=2147483647;
  int i, j;
  i=j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j]){
      p[k]=L[i];
     d[k]=l[i++];
    }
    else{
      p[k]=R[j];
      d[k]=r[j++];
    }
  }
}

void mergeSort(int left, int right){
  if(left>=right-1) return;
  int mid=(left+right)/2;
  mergeSort(left, mid);
  mergeSort(mid, right);
  merge(left, mid, right);
}

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

int *p,*n,*ans,m;

void sort(){
	int tmp;
	for(int i=m; i>0; i--){
		for(int k=0; k<i-1; k++){
			if(p[ans[k]] < p[ans[k+1]] || (p[ans[k]] == p[ans[k+1]] && n[ans[k]] > n[ans[k+1]])){
				tmp = ans[k];
				ans[k] = ans[k+1];
				ans[k+1] = tmp;
			}
		}
	}
}

int main(){
	int pin1,pin2,game,thr;
	bool sp,st1,st2;
	while(true){
		cin >> m;
		if(!m)
			return 0;
		p = new int[m];
		n = new int[m];
		ans = new int[m];
		for(int i=0; i<m; i++){
			sp = false;
			st1 = false;
			st2 = false;
			game = 1;
			cin >> n[i];
			p[i] = 0;
			ans[i] = i;
			while(true){
				cin >> pin1;
				if(sp){
					p[i]+=pin1;
					sp = false;
				}
				if(st2){
					p[i] += pin1;
					st2 = false;
				}
				if(st1){
					p[i] += pin1;
					st2 = true;
					st1 = false;
				}
				if(pin1 == 10){
					st1 = true;
				}else{
					cin >> pin2;
					if(st2){
						p[i] += pin2;
						st2 = false;
					}
					pin1 += pin2;
					if(pin1 == 10)
						sp = true;
				}
				p[i] += pin1;
				game++;
				if(game == 10){
					cin >> pin1;
					if(sp){
						p[i] += pin1;
					}
					if(st2){
						p[i] += pin1;
						st2 = false;
					}
					if(st1){
						p[i] += pin1;
						st2 = true;
					}
					p[i] += pin1;
					if(pin1 == 10){
						cin >> pin1;
						if(st2)
							p[i] += pin1;
						p[i] += pin1;
						cin >> pin1;
						p[i] += pin1;
					}
					else{
						cin >> pin2;
						if(st2)
							p[i] += pin2;
						p[i] += pin2;
						if(pin1 + pin2 == 10){
							cin >> pin1;
							p[i] += pin1;
						}
					}
					break;
				}
			}
		}
		sort();
		for(int i=0; i<m; i++)
			cout << n[ans[i]] << ' ' << p[ans[i]] << endl;
		delete[] n;
		delete[] p;
		delete[] ans;
	}
}