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<algorithm>
using namespace std;
int main(){
	while(1){
	int s[14]={0},pr[14]={0},m,temp=0,count = 0;
	int p[14][4]={0},score[10]={0},score1[10]={0};
	double n[10]={0},n1[10]={0};
	cin >> m;
	if(m==0) return 0;
	for(int i=0;i<m;i++){
		cin >> n[i];
		for(int l=0;l<9;l++){
			for(int k=0;k<2;k++){
				cin >> p[l][k];
				temp+=p[l][k];
				if(k==0&&temp==10){
					s[l] = 1;
					break;
				}else if(k==1&&temp==10){
					pr[l] = 1;
				}else if(k==1&&temp<10){
				}
			}
			temp = 0;
		}
		cin >> p[9][0];
			if(p[9][0] == 10){
				cin >> p[9][1] >> p[9][2];
				score[i]+= 10 + p[9][1] +p[9][2];
			}else{
				cin >> p[9][1];
				if(p[9][0]+p[9][1]==10){
					cin >> p[9][2];
					score[i]+= 10 + p[9][2];
				}
				else score[i]+= p[9][0] + p[9][1];
			}
		for(int a=0;a<8;a++){
			if(s[a]==1){
				if(s[a+1]==0)score[i]+= 10 + p[a+1][0] + p[a+1][1];
				else  score[i]+= 10 + 10 + p[a+2][0];
			}
			else if(pr[a]==1) score[i]+= 10 + p[a+1][0];
			else score[i]+= p[a][0] + p[a][1];
		}
			if(s[8]==0){
				if(pr[8]==1)score[i]+= p[8][0] + p[8][1] + p[9][0];
				else score[i]+= p[8][0] + p[8][1];
			}else score[i]+= 10+p[9][0] +p[9][1];
			for(int h=0;h<14;h++) {
				s[h]=0,pr[h]=0;
				p[h][0]=0,p[h][1];
			}
	}
	for(int i=0;i<m;i++){
		score1[i] = score[i];
	}sort(score1,score1+m);
	for(int i=0;i<m;i++){
		for(int l=0;l<m;l++){
			if(score1[i]==score[l]){
				n1[i] = n[l];
				break;
			}
		}
	}
	for(int i=m-1;i>=0;i--){
		cout << n1[i] << "  " << score1[i] << endl;
	}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,m,score[41][21],id[41],x,cnt,yoso[41]={0},sum[41]={0},flg[41][21],p,check[41]={0};
	
	while(1) {
		cin>>m;
		if(m==0) break;
		for(i=0;i<m;i++) yoso[i]=sum[i]=check[i]=0;
		for(i=0;i<m;i++) {
			cnt=21;
			cin>>id[i];
			x=p=0;
			for(j=0;j<21;j++) flg[i][j]=-1;
			while(cnt>0) {
				cin>>score[i][x];
				if(cnt<=3) {
					if(score[i][x]==10) cnt--,flg[i][x]=2;
					else if(cnt==1&&score[i][x]+score[i][x-1]==10) flg[i][x]=flg[i][x-1]=1;
					else cnt-=2,flg[i][x]=0;
				}	
				else {
					if(score[i][x]==10) cnt-=2,flg[i][x]=2;
					else if(p==1&&score[i][x]+score[i][x-1]==10) flg[i][x]=flg[i][x-1]=1,p=0,cnt--;
					else if(p==1) cnt--,flg[i][x]=0,p=0;
					else cnt--,flg[i][x]=0,p=1;
				}
				x++;
			}
			yoso[i]=x;
		}
		int a;
		for(i=0;i<m;i++) {
			a=0;
			for(j=0;j<yoso[i];j++) {
				if(a!=9) {
					if(flg[i][j]!=2) j++,a++;
					else a++;
				}
				else check[i]++;
			}
		}
		for(i=0;i<m;i++) {
			for(j=0;j<yoso[i];j++) {
				if(j<yoso[i]-check[i]) {
					if(flg[i][j]==0) sum[i]+=score[i][j]+score[i][j+1],j++;
					else if(flg[i][j]==1) {
						sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
						j++;
					}
					else sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
				}
				else {
					if(check[i]==3) sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
					else sum[i]+=score[i][j]+score[i][j+1];
					break;
				}
			}
		}
		for(i=0;i<m-1;i++) {
			for(j=i+1;j<m;j++) {
				if(sum[i]<sum[j]) swap(sum[i],sum[j]),swap(id[i],id[j]);
				if(sum[i]==sum[j]&&id[i]>id[j]) swap(id[i],id[j]); 
			}
		}
		for(i=0;i<m;i++) cout<<id[i]<<" "<<sum[i]<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

struct hoge {
  int id;
  int score;
  hoge(int id, int score) : id(id), score(score) {}
};
bool operator<(const hoge &a, const hoge &b) {
  return (a.score != b.score)? a.score > b.score : a.id < b.id;
}

int main() {
  int n;
  while(cin >> n, n) {
    cin.ignore();
    vector<hoge> w;
    while(n--) {
      stringstream ss;
      string s;
      getline(cin, s);
      ss << s;
      int id;
      ss >> id;
      int a;
      vector<int> v;
      while(ss >> a)
        v.push_back(a);
      int vn = v.size();

      int frame = 0;
      int cnt = 0;
      int score = 0;
      int i=0;
      while(frame < 9) {
        if (cnt == 0) {
          if (v[i] == 10) {
            score += 10 + v[i+1] + v[i+2];
          } else {
            cnt++;
          }
        } else {
          int tmp = v[i-1] + v[i];
          score += tmp;
          if (tmp == 10) {
            score += v[i+1];
          }
          cnt = 0;
        }
        if (cnt == 0)
          frame++;
        
        i++;
      }
      int tmp = v[i] + v[i+1];
      score += tmp;
      if (tmp >= 10) {
        score += v[i+2];
      }
      w.push_back(hoge(id, score));
    }
    sort(ALL(w));
    FOR(it,w) {
      printf("%d %d\n",(*it).id,(*it).score);
    }
  }
}