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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i;
  int s[10][2],f[10],m,p;
  vector<int> d,t;
  for(;;){
    cin>>m;
    if(m==0)
      break;
    d.reserve(m);
    t.reserve(m);
    for(i=0;i<m;i++){
      cin>>p;
      d[i]=p;
      memset(f,0,sizeof(f));
      memset(s,0,sizeof(s));
      for(h=0;h<9;h++){
	cin>>p;
	if(p==10)
	  f[h]=2;
	else{
	  s[h][0]=p;
	  cin>>p;
	  if(p+s[h][0]==10)
	    f[h]=1;
	  else
	    s[h][1]=p;
	}
      }
      cin>>p;
      if(p==10){
	f[h]=2;
	cin>>p;
	s[h][0]=p;
	cin>>p;
	s[h][1]=p;
      }else{
	s[h][0]=p;
	cin>>p;
	if(p+s[h][0]==10){
	  f[h]=1;
	  cin>>p;
	  s[h][1]=p;
	}else
	  s[h][1]=p;
      }
      t[i]=0;
      for(h=0;h<7;h++){
	if(f[h]==0)
	  t[i]+=s[h][0]+s[h][1];
	else if(f[h]==1){
	  if(f[h+1]==2)
	    t[i]+=20;
	  else
	    t[i]+=10+s[h+1][0];
	}else if(f[h]==2){
	  if(f[h+1]==2){
	    if(f[h+2]==2)
	      t[i]+=30;
	    else
	      t[i]+=20+s[h+2][0];
	  }else if(f[h+1]==1)
	    t[i]+=20;
	  else
	    t[i]+=10+s[h+1][0]+s[h+1][1];
	}
      }
      if(f[h]==2){
	if(f[h+1]==2){
	  if(f[h+2]==2)
	    t[i]+=30;
	  else
	    t[i]+=20+s[h+2][0];
	}else if(f[h+1]==1)
	  t[i]+=20;
	else
	  t[i]+=10+s[h+1][0]+s[h+1][1];
      }else if(f[h]==1){
	if(f[h+1]==2)
	  t[i]+=20;
	else
	  t[i]+=10+s[h+1][0];
      }else
	t[i]+=s[h][0]+s[h][1];
      h++;
      if(f[h]==2){
	if(f[h+1]==2)
	  t[i]+=20+s[h+1][0];
	else if(f[h+1]==1)
	  t[i]+=20;
	else
	  t[i]+=10+s[h+1][0]+s[h+1][1];
      }else if(f[h]==1){
	if(f[h+1]==2)
	  t[i]+=20;
	else
	  t[i]+=10+s[h+1][0];
      }else
	t[i]+=s[h][0]+s[h][1];
      h++;
      if(f[h]==2)
	t[i]+=10+s[h][0]+s[h][1];
      else if(f[h]==1)
	t[i]+=10+s[h][1];
      else
	t[i]+=s[h][0]+s[h][1];
    }
    do{
      h=0;
      for(i=1;i<m;i++){
	if(t[i-1]<t[i]){
	  swap(t[i-1],t[i]);
	  swap(d[i-1],d[i]);
	  h=1;
	}else if(t[i-1]==t[i]){
	  if(d[i-1]>d[i]){
	    swap(t[i-1],t[i]);
	    swap(d[i-1],d[i]);
	    h=1;
	  }
	}
      }
    }while(h);
    for(i=0;i<m;i++)
      cout<<d[i]<<" "<<t[i]<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int s[10][5];

P operator+(P a, int d) {
	rep(i, d) {
		if (!~s[a.first][a.second + 1]) {
			a.first++; a.second = 0;
		}
		else a.second++;
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			int id; scanf("%d", &id);
			int f = 0; bool b = 0;
			while (f < 9) {
				scanf("%d", &s[f][b]);
				if (s[f][b] > 10)abort();
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			scanf("%d%d", &s[9][0], &s[9][1]);
			if (s[9][0] == 10 || s[9][1] == 10 || s[9][0] + s[9][1] == 10)scanf("%d", &s[9][2]);
			P p(0, 0);
			while (p.first < 9) {
				if (s[p.first][p.second] == 10) {
					P a = p + 1, b = p + 2;
					s[p.first][p.second] += s[a.first][a.second] + s[b.first][b.second];
				}
				if (p.second&& s[p.first][p.second - 1] + s[p.first][p.second] == 10) {
					P a = p + 1;
					s[p.first][p.second] += s[a.first][a.second];
				}
				p = p + 1;
			}
			int cnt = 0;
			rep(i, 10)rep(j, 3) {
				if (~s[i][j])cnt += s[i][j];
			}
			v.push_back(P(cnt, id));
		}
		sort(v.begin(), v.end(), [](P a, P b) {
			if (a.first != b.first)return a.first > b.first;
			return a.second < b.second;
		});
		for (auto p : v) {
			printf("%d %d\n", p.second, p.first);
		}
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
typedef struct{
  int no,ptpt;
}P;
using namespace std;
int main(){
  string str;
  int n,cnt,score[21],s;

  while(1){
    cin >> n;
    if(n==0)break;
    P p[n];
    for(int l=0;l<n;l++){
      memset(score,0,sizeof(score));
      cin >> p[l].no;
      for(int i=0;i<18;i+=2){
	cin >> s;
	score[i] = s;
	if(s != 10){
	  cin >> s;
	  score[i+1]=s;
	}
      }
      cin >> score[18] >> score[19];
      if(score[18]+score[19]==10 || score[18]==10 || score[19]==10){
	cin >> s;
	score[20] = s;
      }
      int sum=0;
      for(int i=0;i<18;i+=2){
	if(score[i]==10){ //ストライク
	  sum += ((score[i+2]!=10||i==16) ? 10+score[i+2]+score[i+3] :
		  20+score[i+4]);
	} else if(score[i]+score[i+1]==10){ //スペア
	  sum += 10+score[i+2];
	}else 
	sum += score[i]+score[i+1];
      }
      p[l].ptpt = sum + score[18]+score[19]+score[20];
    }

    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(p[j].ptpt>p[j-1].ptpt){
	  swap(p[j],p[j-1]);
	}
      }
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(p[j].ptpt==p[j-1].ptpt&&p[j].no<p[j-1].no){
	  swap(p[j],p[j-1]);
	}
      }
    }
    for(int i=0;i<n;i++){
      cout << p[i].no << " " << p[i].ptpt << endl;
    }
  }   
}