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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int calc_score(vector<int> pins)
{
	int score = 0;
	int frame = 1;
	int frame_cnt = 1;
	int now = 0;

	rep(i,pins.size())
	{
		if (frame != 10)
		{
			if (frame_cnt == 1)
			{
				if (pins[i] == 10)
				{
					//????????¬????????????????????§??????????????????????????????
					score += 10;
					for (int j=i+1; j<=i+2 && j<pins.size(); j++)
						score += pins[j];
					frame++;
					frame_cnt = 1;	
					continue;
				} else {
					score += pins[i];
					frame_cnt++;
					continue;
				}
			} else if (frame_cnt == 2) {
				if (pins[i-1] + pins[i] == 10)
				{
					//????????¢???????????????
					score += pins[i];
					score += pins[i+1];
					frame++;
					frame_cnt = 1;
					continue;
				} else {
					score += pins[i];
					frame++;
					frame_cnt = 1;
					continue;
				}
			}
		} else if (frame == 10) {
			if (frame_cnt == 1)
			{
				if (pins[i] == 10)
				{
					score += 10;
					//for (int j=i+1; j<=i+2 && j<pins.size(); j++)
					//	score += pins[j];
					frame_cnt = 2;
					continue;
				} else {
					score += pins[i];
					frame_cnt = 2;
					continue;
				}
			} else if (frame_cnt == 2) {
				if (pins[i-1] == 10 && pins[i] == 10)
				{
					score += 10;
					//for (int j=i+1; j<=i+2 && j<pins.size(); j++)
					//	score += pins[j];
					frame_cnt = 3;
					continue;
				} else if (pins[i-1] + pins[i] == 10) {
					score += pins[i];
					//score += pins[i+1];
					frame_cnt = 3;
					continue;
				} else {
					score += pins[i];
					break;
				}
			} else if (frame_cnt == 3) {
				score += pins[i];
			}
		}
	}

	return score;
}

int m;
vector<int> ps;
pair<int, int> lst[100];

signed main()
{
	while (true)
	{
		cin >> m;
		if (m == 0) break;
		cin.ignore();
		string str;
		rep(i,m)
		{
			int num;
			ps.clear();

			getline(cin, str);
			//cout << "getline = " << str << endl;
			stringstream ss(str);

			ss >> num;
			//printf("num = %d\n", num);
			for (int x; ss >> x;)
			{
				ps.push_back(x);
			}

			lst[i] = make_pair(-calc_score(ps), num);
		}
	
		sort(lst, lst + m);

		rep(i,m)
		{
			cout << lst[i].second << " " << -lst[i].first << endl;
		}
	}
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int i,j,k;
	int a,s[1000],d[1000][300],f,g[1000],h,z[1000][300],x[1000][300],c,q[1000];
	int aa[1000][300],ss;
	while(1){
		f=0;
		h=0;
		c=0;
		ss=0;
		h=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			q[i]=0;
			for(j=0;j<12;j++) x[i][j]=0;
		}
		for(i=0;i<a;i++){
			f=18;
			g[i]=0;
			scanf("%d",&s[i]);
			while(1){
				scanf("%d",&d[i][g[i]]);
				if(d[i][g[i]]==10) f--;
				g[i]++;
				f--;
				if(f==0) break;
			}
			scanf("%d",&d[i][g[i]]);
			scanf("%d",&d[i][g[i]+1]);
			if(d[i][g[i]]==10||d[i][g[i]+1]==10||d[i][g[i]]+d[i][g[i]+1]==10){
				scanf("%d",&d[i][g[i]+2]);
				g[i]++;
			}
			g[i]+=2;
		}
		for(i=0;i<a;i++){
			j=0;
			c=0;
			while(1){
				if(d[i][j]==10){
					z[i][c]=2;
					x[i][c]=10;
					ss++;
					j++;
					aa[i][c]=j;
					c++;
				}
				else if(d[i][j]+d[i][j+1]==10){
					z[i][c]=1;
					x[i][c]=10;
					j=j+2;
					aa[i][c]=j;
					c++;
				}
				else if(d[i][j]+d[i][j+1]!=10){
					z[i][c]=0;
					x[i][c]=d[i][j]+d[i][j+1];
					j=j+2;
					aa[i][c]=j;
					c++;
				}
				else if(j=g[i]-1&&d[i][j]!=10){
					x[i][c]=d[i][j];
					z[i][c]=0;
					j++;
					aa[i][c]=j;
					c++;
				}
				if(j>=g[i])	break;
			}
		}
		for(i=0;i<a;i++){
			for(j=0;j<9;j++){
				q[i]+=x[i][j];
				if(z[i][j]==2){
					if(z[i][j+1]==2){
						if(z[i][j+2]==2)
							q[i]=q[i]+x[i][j+1]+x[i][j+2];
						else if(z[i][j+2]!=2)
							q[i]=q[i]+x[i][j+1]+d[i][aa[i][j+1]];
					}
					else if(z[i][j+1]!=2){
						q[i]+=x[i][j+1];
					}
				}
				else if(z[i][j]==1){
					q[i]+=d[i][aa[i][j]];
				}
			}
			q[i]=q[i]+x[i][9]+x[i][10]+x[i][11];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(q[i]<q[j]){
					ss=q[i];
					q[i]=q[j];
					q[j]=ss;
					ss=s[i];
					s[i]=s[j];
					s[j]=ss;
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%d %d\n",s[i],q[i]);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
using namespace std;

unordered_map<int, int>U;
int r[40];
vector<int>bunkatu(string a) {
	a += " ";
	vector<int>V;
	string b;
	for (char c : a) {
		if (c == ' ') { V.push_back(stoi(b)); b = ""; }
		else b += c;
	}
	return V;
}
int main(){
	int a;
	while (cin >> a, a) {
		U.clear();
		for (int l = 0; l < a; l++) {
			int n; cin >> n;
			r[l] = n;
			string b; getline(cin, b);
			b = b.substr(1, b.length() - 1);
			vector<int>V = bunkatu(b);
			int now = 0;
			int sum = 0;
			for (int i = 0; i < 10; i++) {
				if (V[now] == 10) {
					sum += 10 + V[now+1] + V[now+2];
					now++;
					continue;
				}
				int k = V[now] + V[now + 1];
				if (k == 10)k += V[now + 2];
				sum += k;
				now += 2;
			}
			U[n] = sum;
		}
		sort(r, r + a, [](int a, int b) {if (U[a] != U[b])return U[a] > U[b]; return a < b; });
		for (int i = 0; i < a; i++) {
			cout << r[i] << " " << U[r[i]] << endl;
		}
	}
}