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 <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] + 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++: test

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int i,j,k;
long long int a,s[100000],d[50000][30],f,g[100000],h,z[100000][30],x[100000][30],c,q[100000];
long long int aa[100000][30],ss;
int main(void)
{
	while(1){
		f=0;
		h=0;
		c=0;
		ss=0;
		h=0;
		scanf("%lld",&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("%lld",&s[i]);
			while(1){
				scanf("%lld",&d[i][g[i]]);
				if(d[i][g[i]]==10) f--;
				g[i]++;
				f--;
				if(f==0) break;
			}
			scanf("%lld",&d[i][g[i]]);
			scanf("%lld",&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("%lld",&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<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("%lld %lld\n",s[i],q[i]);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int n,num[50],score[50]={0},tmp;
	int s_max,ans_num;
	vector<int> pin;

	while(cin>>n){
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>num[i];
			score[i]=0; pin.clear();
			for(int j=0;j<9;j++){
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
				if(tmp==10) continue;
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			}

			cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			if(pin[pin.size()-2]==10 || pin[pin.size()-1]+pin[pin.size()-2]==10){
				cin>>tmp; score[i]+=tmp; pin.push_back(tmp);
			}


			for(int j=0,k=0;j<9;j++){
				if(pin[k]==10){
					score[i]+=pin[k+1]+pin[k+2]; k++;
				}else if(pin[k]+pin[k+1]==10){
					score[i]+=pin[k+2]; k+=2;
				}else{k+=2;}
			}

		}
		
		for(int i=0;i<n;i++){
			s_max=-1;
			for(int j=0;j<n;j++){
				if(score[j]>s_max){ s_max=score[j]; ans_num=j;}
			}
			cout<<num[ans_num]<<" "<<score[ans_num]<<endl;
			score[ans_num]=0;
		}
	}
	
	return 0;
}