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 <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

bool cmp(const pair<int,int> &a,const pair<int,int> &b){
    return a.second < b.second;
}

void solve(vector<vector<int> > v){
    map<int,int> point2num;
    vector<pair<int,int> > points;
    for(int i=0;i<v.size();i++){
        int num = v[i][0];
        vector<int> frame(11);
        frame[0] = 0;
        int f=1;int j=1;
        while(true){
            if(f==11)break;
            int x = v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1]+v[i][j+2];
                f++;j++;
                continue;
            }
            j++;
            x = x+v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1];
                f++;j++;
                continue;
            }
            frame[f] = x;
            f++;j++;
            continue;
        }
        int p=0;
        for(int j=0;j<frame.size();j++){
            p+=frame[j];
        }
        points.push_back(make_pair(num,p));
    }
    sort(points.begin(),points.end());
    reverse(points.begin(),points.end());
    stable_sort(points.begin(),points.end(),cmp);
    reverse(points.begin(),points.end());
    for(int i=0;i<points.size();i++){
        cout << points[i].first << " " << points[i].second << endl;
    }
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        cin.ignore();
        vector<vector<int> > v(n);
        for(int i=0;i<n;i++){
            string s;
            getline(cin,s);
            istringstream is(s);
            int x;
            while(is >> x){
                v[i].push_back(x);
            }
        }
        solve(v);
    }
}

C++: #include<iostream>
#include<cstring>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;

#define MAX_N 24000

int game[MAX_N][12], x[MAX_N][12][10];
int score[MAX_N][12];
int sum[MAX_N], cust[MAX_N];
int n, cnt, sum2;

pair<int, int>bowling[MAX_N];

int main() {
	while (true) {
		//memset.
		memset(game, 0, sizeof(game));
		memset(x, 0, sizeof(x));
		memset(score, 0, sizeof(score));
		memset(sum, 0, sizeof(sum));
		memset(cust, 0, sizeof(cust));
		memset(bowling, 0, sizeof(bowling));

		cin >> n;
		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			cin >> cust[i];

			for (int j = 0; j < 10; j++) {
				//cin.
				cnt = 0;
				while (true) {
					cin >> x[i][j][cnt];

					//1-9 Frame.
					if (j < 9) {
						if (x[i][j][cnt] == 10) {
							goto Exit;
						}
						if (cnt == 1) {
							goto Exit;
						}
					}

					//10 Frame.
					else {
						if (cnt == 1) {
							if (x[i][j][0] != 10 && x[i][j][0] + x[i][j][1] != 10) {
								goto Exit;
							}
						}
						else if (cnt == 2) {
							goto Exit;
						}
					}

					//End Throw.
					cnt++;
				}
			Exit:;
				game[i][j] = cnt + 1;
			}
		}
		
		//check.
		for (int i = 0; i < n; i++) {

			//sum.
			for (int j = 0; j < 10; j++) {
				sum2 = 0;
				for (int k = 0; k < game[i][j]; k++) {
					sum2 += x[i][j][k];
				}

				//1-9 Frame.
				if (j < 9) {
					//Normal.
					if (sum2 < 10) {
						score[i][j] = sum2;
					}

					//Spair.
					else if (game[i][j] == 2) {
						score[i][j] = 10 + x[i][j + 1][0];
					}

					//Strike!!
					else {
						if (game[i][j + 1] == 1) {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 2][0];
						}
						else {
							score[i][j] = 10 + x[i][j + 1][0] + x[i][j + 1][1];
						}
					}
				}

				//10 Frame.
				else {
					score[i][j] = sum2;
				}
			}

			//Calc.
			for (int j = 0; j < 10; j++) {
				sum[i] += score[i][j];
			}
		}

		//pair-input.
		for (int i = 0; i < n; i++) {
			bowling[i] = make_pair(sum[i], cust[i]);
		}

		//sort.
		sort(bowling, bowling + n, greater<pair<int, int> >());

		//print.
		for (int i = 0; i < n; i++) {
			cout << bowling[i].second << ' ' << bowling[i].first << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int s[10][5];

P operator+(P a, int d) {
	rep(i, d) {
		if (!~s[a.first][a.second + 1]) {
			a.first++; a.second = 0;
		}
		else a.second++;
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			int id; scanf("%d",&id);
			int f = 0; bool b = 0;
			while (f < 9) {
				char c;
				scanf("%c%d", &c,&s[f][b]);
				if (c == '\n')abort();
				//if (s[f][b] > 10)abort();
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			scanf("%d%d", &s[9][0], &s[9][1]);
			if (s[9][0] == 10 || s[9][1] == 10 || s[9][0] + s[9][1] == 10)scanf("%d", &s[9][2]);
			P p(0, 0);
			while (p.first < 9) {
				if (s[p.first][p.second] == 10) {
					P a = p + 1, b = p + 2;
					s[p.first][p.second] += s[a.first][a.second] + s[b.first][b.second];
				}
				if (p.second&& s[p.first][p.second - 1] + s[p.first][p.second] == 10) {
					P a = p + 1;
					s[p.first][p.second] += s[a.first][a.second];
				}
				p = p + 1;
			}
			int cnt = 0;
			rep(i, 10)rep(j, 3) {
				if (~s[i][j])cnt += s[i][j];
			}
			v.push_back(P(cnt, id));
		}
		sort(v.begin(), v.end(), [](P a, P b) {
			if (a.first != b.first)return a.first > b.first;
			return a.second < b.second;
		});
		for (auto p : v) {
			printf("%d %d\n", p.second, p.first);
		}
	}
}