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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		vector<pint> vp(n);
		int i;
		int f,s1,s2;
		int d;
		int score;
		for(i=0;i<n;i++){
			f=1;
			d=0;
			score=0;
			cin>>vp[i].second;
			while(f<10){
				cin>>s1;
				if(d==3){
					score+=s1*3;
				}else if(d==0){
					score+=s1;
				}else{
					score+=s1*2;
				}
				d/=2;
				if(s1==10){
					d|=2;
				}else{
					cin>>s2;
					if(d==0){
						score+=s2;
					}else{
						score+=s2*2;
					}
					d=0;
					if(s1+s2==10)d=1;
				}
				f++;
			}
			cin>>s1;
			if(d==3){
				score+=s1*3;
			}else if(d==0){
				score+=s1;
			}else{
				score+=s1*2;
			}
			d/=2;
			cin>>s2;
			if(d==0){
				score+=s2;
			}else{
				score+=s2*2;
			}
			if(s1+s2>=10){
				score+=in();
			}
			vp[i].first=score;
		}
		while(!vp.empty()){
			int r=0;
			for(i=1;i<vp.size();i++){
				if(vp[r].first<vp[i].first||vp[r].first==vp[i].first&&vp[r].second>vp[i].second)
					r=i;
			}
			cout<<vp[r].second<<" "<<vp[r].first<<endl;
			vp[r]=vp[vp.size()-1];
			vp.pop_back();
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

class data{
public:
	int num,score;
	data(int nn,int sc){
		num=nn;
		score=sc;
	}
	bool operator<(const data& da)const{
		if(da.score==score)return da.num>num;
		return da.score<score;
	}
};

int m;
int num[10000];
int score[10000][11][2],pts[11],sp,st[11];
vector<data> d;

int main(void){
	while(1){
		scanf("%d",&m);
		if(m==0)break;
		d.clear();
		for(int i=0;i<m;i++){
			scanf("%d",&num[i]);
			sp=0;
			for(int j=0;j<10;j++){
				scanf("%d",&score[i][j][0]);
				if(sp==1){
					pts[j-1]+=score[i][j][0];
					sp=0;
				}
				if(j>0 && st[j-1]>0){
					pts[j-1]+=score[i][j][0];
					st[j-1]--;
				}
				if(j>1 && st[j-2]>0){
					pts[j-2]+=score[i][j][0];
					st[j-2]--;
				}
				if(score[i][j][0]==10){
					if(j==9){
						scanf("%d %d",&score[i][j][1],&score[i][j][2]);
						pts[9]=score[i][j][0]+score[i][j][1]+score[i][j][2];
						if(j>0 && st[j-1]>0){
							pts[j-1]+=score[i][j][1];
							st[j-1]--;
						}
						if(j>1 && st[j-2]>0){
							pts[j-2]+=score[i][j][1];
							st[j-2]--;
						}
					}else{
						st[j]=2;
						pts[j]=10;
					}
				}else{
					scanf("%d",&score[i][j][1]);
					if(score[i][j][0]+score[i][j][1]==10){
						if(j==9){
							scanf("%d",&score[i][j][2]);
							pts[9]=10+score[i][j][2];
						}else{
							pts[j]=10;
							sp=1;
						}
					}else pts[j]=score[i][j][0]+score[i][j][1];
					if(j>0 && st[j-1]>0){
						pts[j-1]+=score[i][j][1];
						st[j-1]--;
					}
					if(j>1 && st[j-2]>0){
						pts[j-2]+=score[i][j][1];
						st[j-2]--;
					}
				}
			}
			int sc=0;
			for(int j=0;j<10;j++){
				sc+=pts[j];
			}
			d.push_back(data(num[i],sc));
		}
		sort(d.begin(),d.end());
		for(int i=0;i<m;i++){
			printf("%d %d\n",d[i].num,d[i].score);
		}
	}
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int a,s[10000],d[10000][30],f,g[10000],h,j,i,k,z[10000][30],x[10000][30],c,q[10000];
int aa[10000][30],ss;
int main(void)
{
	while(1){
		h=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			q[i]=0;
			for(j=0;j<12;j++) x[i][j]=0;
		}
		for(i=0;i<a;i++){
			f=18;
			g[i]=0;
			scanf("%d",&s[i]);
			while(1){
				scanf("%d",&d[i][g[i]]);
				if(d[i][g[i]]==10) f--;
				g[i]++;
				f--;
				if(f==0) break;
			}
			scanf("%d",&d[i][g[i]]);
			scanf("%d",&d[i][g[i]+1]);
			if(d[i][g[i]]==10||d[i][g[i]+1]==10||d[i][g[i]]+d[i][g[i]+1]==10){
				scanf("%d",&d[i][g[i]+2]);
				g[i]++;
			}
			g[i]+=2;
		}
		for(i=0;i<a;i++){
			j=0;
			c=0;
			while(1){
				if(d[i][j]==10){
					z[i][c]=2;
					x[i][c]=10;
					ss++;
					j++;
					aa[i][c]=j;
					c++;
				}
				else if(d[i][j]+d[i][j+1]==10){
					z[i][c]=1;
					x[i][c]=10;
					j=j+2;
					aa[i][c]=j;
					c++;
				}
				else if(d[i][j]+d[i][j+1]!=10){
					z[i][c]=0;
					x[i][c]=d[i][j]+d[i][j+1];
					j=j+2;
					aa[i][c]=j;
					c++;
				}
				else if(j=g[i]-1&&d[i][j]!=10){
					x[i][c]=d[i][j];
					z[i][c]=0;
					j++;
					aa[i][c]=j;
					c++;
				}
				if(j>=g[i])	break;
			}
		}
		for(i=0;i<a;i++){
			for(j=0;j<12;j++){
				printf("%d ",aa[i][j]);
			}
			printf("\n");
		}
		for(i=0;i<a;i++){
			for(j=0;j<9;j++){
				q[i]+=x[i][j];
				if(z[i][j]==2){
					if(z[i][j+1]==2){
						if(z[i][j+2]==2)
							q[i]=q[i]+x[i][j+1]+x[i][j+2];
						else if(z[i][j+2]!=2)
							q[i]=q[i]+x[i][j+1]+d[i][aa[i][j+1]];
					}
					else if(z[i][j+1]!=2){
						q[i]+=x[i][j+1];
					}
				}
				else if(z[i][j]==1){
					q[i]+=d[i][aa[i][j]];
					printf("1  %d\n",d[i][aa[i][j]]);
				}
			}
			q[i]=q[i]+x[i][9]+x[i][10]+x[i][11];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(q[i]<q[j]){
					ss=q[i];
					q[i]=q[j];
					q[j]=ss;
					ss=s[i];
					s[i]=s[j];
					s[j]=ss;
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%d %d\n",s[i],q[i]);
		}
	}
	/*for(i=0;i<a;i++){
		for(j=0;j<12;j++){
			printf("|%d %d| ",z[i][j],x[i][j]);
		}
		printf("\n");
	}*/
	return 0;
}