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 <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


vi getInput(){
    vi ret;
    
    rep(i,9){
        int a,b;
        cin>>a;
        ret.pb(a);
        
        if(a<10){
            cin>>b;
            ret.pb(b);
        }
    }
    
    int a,b,c;
    cin>>a;
    cin>>b;
    ret.pb(a);
    ret.pb(b);

    if(a+b>=10){
        cin>>c;
        ret.pb(c);
    }

    
    return ret;
}



int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        
        vector<pii> data;
        rep(i,n){
            int gNum;
            cin>>gNum;
            
            vi in=getInput();
            int len=in.size();

            int sum=0;
            int c=0;
            rep(i,9){
                if(in[c]==10){
                    sum+=10+in[c+1]+in[c+2];
                    c++;
                }
                else if(in[c]+in[c+1]==10){
                    sum+=10+in[c+2];
                    c+=2;
                }
                else{
                    sum+=in[c]+in[c+1];
                    c+=2;
                }

            }
            while(c<len){
                sum+=in[c];
                c++;
            }
            data.pb(pii(sum,gNum));
        }
        
        rep(i,data.size()-1){
            for(int j=i+1;j<data.size();j++){
                if( data[i].first<data[j].first || (data[i].first==data[j].first && data[i].second>data[j].second) ){
                    swap(data[i],data[j]);
                }
            }
        }
        rep(i,data.size()){
            cout<<data[i].second<<" "<<data[i].first<<endl;
        }
        
    }
    return 0;
}



//3
//1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
//1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
//1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > score(n);
        for(int i=0; i<n; ++i){
            cin >> score[i].second;
            score[i].second = -score[i].second;

            vector<vector<int> > pin(10, vector<int>(2, 0));
            for(int j=0; j<10; ++j){
                cin >> pin[j][0];
                if(j == 9 || pin[j][0] != 10)
                    cin >> pin[j][1];
                score[i].first += pin[j][0] + pin[j][1];

                if(j > 0 && pin[j-1][0] == 10){
                    score[i].first += pin[j][0] + pin[j][1];
                    if(j > 1 && pin[j-2][0] == 10)
                        score[i].first += pin[j][0];
                }
                else if(j > 0 && pin[j-1][0] + pin[j-1][1] == 10)
                    score[i].first += pin[j][0];
            }
            if(pin[9][0] == 10 || pin[9][0] + pin[9][1] == 10){
                int a;
                cin >> a;
                score[i].first += a;
            }
        }

        sort(score.rbegin(), score.rend());
        for(int i=0; i<n; ++i)
            cout << -score[i].second << ' ' << score[i].first << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,m,score[42][22],id[42],x,cnt,yoso[42],sum[42],flg[42][22],p,check[42];
	
	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]-check[i];j++) {
				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];
			}
			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];
		}
		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;
	}
}