Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

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 <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


II solve( int no, VI A ) {
    VI F(10, 0), S(10, 0), C(10, 0);
    VI T(10, 0);
    int t = 0;
    for ( int i = 0; i < 10; ++ i ) {
        F[i] = 0, S[i] = 0, C[i] = 0;
        if ( i == 9 ) {
            F[i] = A[t++];
            S[i] = A[t++];
            C[i] = 0;
            if ( F[i] == 10 || S[i] == 10 || F[i] + S[i] == 10 ) C[i] = A[t++];
        } else {
            if ( A[t] == 10 ) {
                F[i] = A[t++];
            } else {
                F[i] = A[t++];
                S[i] = A[t++];
            }
        }
    }

    for ( int i = 0; i < 10; ++ i ) {
        T[i] = F[i] + S[i] + C[i];
    }

    int addScore = 0;
    for ( int i = 0; i < 9; ++ i ) {
        if ( F[i] == 10 ) {
            if ( i < 8 ) {
                if ( F[i+1] == 10 ) {
                    addScore += 10 + F[i+2];
                } else {
                    addScore += F[i+1] + S[i+1];
                }
            } else if ( i == 8 ) {
                addScore += F[9] + S[9];
            }
        } else if ( F[i] + S[i] == 10 ) {
            addScore += F[i+1];
        }
    }
    return II( accumulate( T.begin(), T.end(), 0 ) + addScore, no );
}

int main() {
    string line;
    while ( getline( cin, line ) ) {
        if ( line == "0" ) break;
        ISS iss( line );
        int n;
        iss >> n;
        VII scores( n );
        for ( int i = 0; i < n; ++ i ) {
            getline( cin, line );
            ISS iss( line );
            int no;
            iss >> no;
            int a;
            VI A;
            while ( iss >> a ) A.push_back( a );
            scores[i] = solve( no, A );
        }
        sort( scores.rbegin(), scores.rend() );
        for ( int i = 0; i < n; ++ i ) {
            cout << scores[i].second << " " << scores[i].first << endl; 
        }
    }
    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 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;
}