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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    while(1){
        int m; cin>>m;
        if(m == 0) return 0;

        vector<int> id(m);
        vector<vector<int>> score(m);
        for(int i=0; i<m; i++){
            cin>>id[i];
            
            int turn = 1;
            int cnt = 0;
            int sum = 0;
            while(1){
                int s; cin>>s;
                score[i].eb(s);
                sum += s;
                cnt++;

                if(turn == 10){
                    if(sum == 10){
                        int s1, s2; cin>>s1>>s2;
                        score[i].eb(s1);
                        score[i].eb(s2);
                    }
                    else{
                        int s1; cin>>s1;
                        if(s + s1 == 10){
                            int s2; cin>>s2;
                            score[i].eb(s1);
                            score[i].eb(s2);
                        }
                        else{
                            score[i].eb(s1);
                        }
                    }

                    break;
                }

                if(sum == 10 && cnt == 1){
                    cnt = 0;
                    turn++;
                    sum = 0;
                }
                else if(sum == 10 && cnt == 2){
                    cnt = 0;
                    turn++;
                    sum = 0;
                }
                else if(cnt == 2){
                    cnt = 0;
                    turn++;
                    sum = 0;
                }
            }
        }

        vector<P> fans(m);
        for(int i=0; i<m; i++){
            int ID = id[i];
            int turn = 1;
            int cnt = 0;
            int sum = 0;
            int ans = 0;
            for(int j=0; j<score[i].size(); j++){
                sum += score[i][j];
                ans += score[i][j];
                cnt++;

                if(turn == 10) continue;

                if(sum == 10 && cnt == 1){
                    ans += score[i][j+1];
                    ans += score[i][j+2];
                    turn++;
                    cnt = 0;
                    sum = 0;
                }
                else if(sum == 10 && cnt == 2){
                    ans += score[i][j+1];
                    turn++;
                    cnt = 0;
                    sum = 0;
                }
                else if(cnt == 2){
                    turn++;
                    cnt = 0;
                    sum = 0;
                }
            }

            fans[i] = P(ans, ID);
        }

        sort(fans.begin(), fans.end(), greater<P>());

        for(int i=0; i<m; i++){
            cout << fans[i].second << " " << fans[i].first << endl;
        }
    }
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

struct bowling
{
	int id,score;
	//bowling(int id,int score):id(id),score(score){};
	bool operator <(const bowling &t)const{
		if(score!=t.score)return score >t.score;
		return id <t.id;
	}
};

int main(){
	int n;
	while(cin>>n,n){
		bowling data[40];
		int pos = 0;
		int N =n;
		cin.ignore();
		while(n--){
			string str;
			getline(cin,str);
			//cout <<"str = "<<str<<endl;
			stringstream ss(str);
			int id;
			ss >>id;
			int a[30]={0};
			for(int j =0;ss>>a[j];){
				j++;
			}
			//cout <<"test"<<endl;
			int scr = 0;
			int x = 0;
			//cout <<"pos = "<<pos<<endl;
			for(int i =1;;i++){
				if(i!=10){
					if(a[x]==10){
						scr +=(10+a[x+1]+a[x+2]);
						x++;
					}
					else if(a[x]+a[x+1]==10){
						scr +=(10+a[x+2]);
						x +=2;
					}else{
						scr +=(a[x]+a[x+1]);
						x +=2;
					}
				}else{
					scr +=(a[x]+a[x+1]+a[x+2]);
					break;
				}
			}
			bowling cs={id,scr};
			data[pos++] =cs;
		}
		sort(data,data+N);
		for(int i =0;i <N;i++){
			cout <<data[i].id<<" "<<data[i].score<<endl;
		}
	}
	return 0;
}