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 <vector>
#include <algorithm>
#include <iostream>

using namespace std;

struct Frame {
    int one, two, third, score;
    bool strike, spare;
    Frame() { score = 0; strike = spare = false; one = two = third = 0; }
};

struct Player {
    int id, score;
    Player() {}
};

bool operator < (const Player &a, const Player &b)
{
    return (a.score == b.score) ? (a.id < b.id) : (a.score > b.score);
}

int Caluculate(string s)
{
    int data[22];
    int n = 0, index = 1;

    // parse number
    while (index < s.size()) {
        int num = 0;
        while (true) {
            if ('0' <= s[index] && s[index] <= '9') {
                num *= 10;
                num += (int)(s[index++] - '0');
            }
            else
                break;
        }
        index++;
        data[n++] = num;
    }

    // スコア
    Frame frame[10];
    double game = 1.0;
    for (int i = 0; i < n; ++i) {
        if (game >= 10.0) { // 10ゲーム目
            frame[9].score += data[i];
            if (game == 10.0)
                frame[9].one = data[i];
            else if (game == 10.5)
                frame[9].two = data[i];
            else if (game == 11.0)
                frame[9].third = data[i];
            game += 0.5;
        }
        else if (game - (int)game != 0.0) {  // 後半
            if (frame[(int)game - 1].one + data[i] == 10) // スペア
                frame[(int)game - 1].spare = true;
            frame[(int)game - 1].two = data[i];
            game += 0.5;
        }
        else { // 前半
            if (data[i] == 10) { // ストライク
                frame[(int)game - 1].one = 10;
                frame[(int)game - 1].strike = true;
                game += 1.0;
            }
            else {
                frame[(int)game - 1].one = data[i];
                game += 0.5;
            }
        }
    }

    // 各フレーム(1-9)でのスコア計算
    for (int i = 0; i < 9; ++i) {
        if (frame[i].spare) // スペア
            frame[i].score = 10 + frame[i + 1].one;
        else if (frame[i].strike) { // ストライク
            frame[i].score = 10;
            if (i == 8) // 第9ホール
                frame[i].score += frame[i + 1].one + frame[i + 1].two;
            else if (frame[i + 1].strike)
                frame[i].score += 10 + frame[i + 2].one;
            else
                frame[i].score += frame[i + 1].one + frame[i + 1].two;
        }
        else
            frame[i].score = frame[i].one + frame[i].two;
    }

    // ゲームのスコア計算
    int res = 0;
    for (int i = 0; i < 10; ++i)
        res += frame[i].score;

    return res;
}

int main()
{
    int m;

    while (cin >> m, m) {
        vector<Player> player(m);

        // Input
        for (int i = 0; i < m; ++i) {
            string data;
            cin >> player[i].id;
            getline(cin, data);

            player[i].score = Caluculate(data);
        }

        sort(player.begin(), player.end());

        // Output
        for (int i = 0; i < m; ++i)
            cout << player[i].id << " " << player[i].score << endl;
    }

    return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pii> v;
		rep(i,n){
			vector<pii> tt;
			int id;
			cin>>id;
			int t;
			int cnt=1;
			while(1){
				cin>>t;
				if(cnt==10){
					int a=t;
					if(a==10){
						tt.PB(mkp(a,cnt));
						cin>>t;
						tt.PB(mkp(t,cnt));
						cin>>t;
						tt.PB(mkp(t,cnt));
						break;
					}
					else{
						tt.PB(mkp(t,cnt));
						cin>>t;
						tt.PB(mkp(t,cnt));
						if(a+t==10){
							cin>>t;
							tt.PB(mkp(t,cnt));	
						}
						break;
						
					}
				}
				else if(t==10){
					tt.PB(mkp(t,cnt));
				}
				else{
					tt.PB(mkp(t,cnt));
					cin>>t;
					tt.PB(mkp(t,cnt));
				}
				cnt++;
			}
			int tmp=0;
			// cout<<"id = "<<id<<endl;
			// rep(i,tt.size()){
				// cout<<tt[i].F<<" "<<tt[i].S<<endl;
			// }
			// cout<<endl;
			rep(i,tt.size()){
				if(tt[i].S==10){
					tmp+=tt[i].F;
					continue;
				}
				if(tt[i].F==10){
					tmp+=10+tt[i+1].F+tt[i+2].F;
					continue;
				}
				if(tt[i].F+tt[i+1].F==10){
					tmp+=10+tt[i+2].F;
					i++;
				}
				else{
					tmp+=tt[i].F+tt[i+1].F;
					i++;
				}
			}
			v.PB(mkp(-tmp,id));
		}
		sort(ALL(v));
		rep(i,n) cout<<v[i].S<<" "<<-v[i].F<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}