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 <cstdlib>
#include <vector>
#include <map>
#include <string>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		map<P, int> Map;
		for(int i = 0; i < n; ++i)
		{
			int num;
			cin >> num;
			P p;
			p.second = num;
			string str;
			getline(cin, str);
			str += " ";
			int size = str.size();
			vector<int> Vec;
			int s = 0;
			for(int j = 1; j < size; ++j)
			{
				if(str[j] == ' ')
				{
					Vec.push_back(s);
					s = 0;
				}
				else
				{
					s *= 10;
					s += str[j] - '0';
				}
			}
			int sum = 0;
			size = Vec.size();
			Vec.push_back(0);
			Vec.push_back(0);
			int count = 0;
			int bonus = 0;
			int point = 0;
			int frame = 0;
			for(int i = 0; i < size; ++i)
			{
				if(count % 2 == 0)
				{
					count %= 2;
					point = 0;
					++frame;
				}
				++count;
				if(frame >= 10)
				{
					sum += Vec[i];
					continue;
				}
				point += Vec[i];
				sum += Vec[i];
				if(count == 2 && point == 10)		//spare
				{
					bonus = 1;
				}
				if(count == 1 && point == 10)		//strike
				{
					bonus = 2;
					count = 2;
				}
				if(bonus == 1)
				{
					sum += Vec[i + 1];
					bonus = 0;
				}
				else if(bonus == 2)
				{
					sum += Vec[i + 1] + Vec[i + 2];
					bonus = 0;
				}				
			}
			p.first = sum;
			++Map[p];
		}
		map<P, int>::iterator It = Map.end();
		--It;
		for(int i = 0; i < n; ++i)
		{
			cout << It->first.second << " " << It->first.first << endl;
			--It;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
pair<int,int> d[40];
int cnt,sparecnt,throwcnt;
int plus[2];
int numcnt;
void Sc(int u){
	if(numcnt>9)plus[0]--;
	if(numcnt>10)plus[0]--;
	d[u].first+=cnt*plus[0];
	plus[0]=plus[1];
	plus[1]=1;
	throwcnt++;
	sparecnt+=cnt;
	if(throwcnt==2){
		if(sparecnt==10){
			plus[0]++;
		}
		throwcnt=0;
		sparecnt=0;
		numcnt++;
	}
	if(cnt==10){
		plus[0]++;
		plus[1]++;
		throwcnt=0;
		sparecnt=0;
		numcnt++;
	}
	cnt=0;
}
int main(){
	int m;
	while(true){
	cin>>m;
	if(!m)break;
	string s;
	for(int u=0;u<m;u++){
		cin>>d[u].second;
		getline(cin,s);
		d[u].second=10000-d[u].second;
		d[u].first=0;
		cnt=0,sparecnt=0,throwcnt=-1;
		plus[0]=1,plus[1]=1;
		numcnt=0;
		for(int i=0;i<s.size();i++){
			if(s[i]==' '){
				Sc(u);
			}
			else{
				cnt*=10;
				cnt+=s[i]-'0';
			}
		}
		Sc(u);
	}
	sort(d,d+m);
	for(int i=m-1;i>=0;i--){
		cout<<10000-d[i].second<<" "<<d[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.second++;
		else {
			a.first++; a.second = 0;
		}
	}
	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, cnt = 0;
			while (f < 9) {
				scanf("%d", &s[f][cnt]);
				if (s[f][cnt] > 10)abort();
				if (s[f][cnt] == 10)f++;
				else if (cnt) {
					f++; cnt = 0;
				}
				else cnt++;
			}
			scanf("%d%d", &s[9][0], &s[9][1]);
			if (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;
			}
			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);
		}
	}
}

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[30][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%*c", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			string S; getline(cin, S);
			stringstream buf(S);
			int id; buf >> id;
			int f = 1; bool b = 0;
			while (f <= 9) {
				if (!(buf >> s[f][b]))abort();
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			buf >> s[10][0] >> s[10][1];
			if (s[10][0] == 10 || s[10][1] == 10 || s[10][0] + s[10][1] == 10)buf >> s[10][2];
			P p(1, 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;
			for (int i = 1; i <= 10; i++)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);
		}
	}
}