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>
using namespace std;
int main(void)
{
	int i,j,k,m,score[41][21],id[41],x,cnt,yoso[41]={0},sum[41]={0},flg[41][21],p,check[41]={0};
	
	while(1) {
		cin>>m;
		if(m==0) break;
		for(i=0;i<m;i++) yoso[i]=sum[i]=check[i]=0;
		for(i=0;i<m;i++) {
			cnt=21;
			cin>>id[i];
			x=p=0;
			for(j=0;j<21;j++) flg[i][j]=-1;
			while(cnt>0) {
				cin>>score[i][x];
				if(cnt<=3) {
					if(score[i][x]==10) cnt--,flg[i][x]=2;
					else if(cnt==1&&score[i][x]+score[i][x-1]==10) flg[i][x]=flg[i][x-1]=1;
					else cnt-=2,flg[i][x]=0;
				}	
				else {
					if(score[i][x]==10) cnt-=2,flg[i][x]=2;
					else if(p==1&&score[i][x]+score[i][x-1]==10) flg[i][x]=flg[i][x-1]=1,p=0,cnt--;
					else if(p==1) cnt--,flg[i][x]=0,p=0;
					else cnt--,flg[i][x]=0,p=1;
				}
				x++;
			}
			yoso[i]=x;
		}
		int a;
		for(i=0;i<m;i++) {
			a=0;
			for(j=0;j<yoso[i];j++) {
				if(a!=9) {
					if(flg[i][j]!=2) j++,a++;
					else a++;
				}
				else check[i]++;
			}
		}
		for(i=0;i<m;i++) {
			for(j=0;j<yoso[i];j++) {
				if(j<yoso[i]-check[i]) {
					if(flg[i][j]==0) sum[i]+=score[i][j]+score[i][j+1],j++;
					else if(flg[i][j]==1) {
						sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
						j++;
					}
					else sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
				}
				else {
					if(check[i]==3) sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
					else sum[i]+=score[i][j]+score[i][j+1];
					break;
				}
			}
		}
		for(i=0;i<m-1;i++) {
			for(j=i+1;j<m;j++) {
				if(sum[i]<sum[j]) swap(sum[i],sum[j]),swap(id[i],id[j]);
				if(sum[i]==sum[j]&&id[i]>id[j]) swap(id[i],id[j]); 
			}
		}
		for(i=0;i<m;i++) cout<<id[i]<<" "<<sum[i]<<endl;
	}
}

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

map<int, int>U;
vector<int>r;
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();
		r.clear();
		for (int l = 0; l < a; l++) {
			int n; cin >> n;
			r.push_back(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.begin(),r.end(), [](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;
		}
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <functional>

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

void solve()
{
	int m;
	while(cin >> m, m)
	{
		cin.ignore();
		vector< vector<int> > Point(m); 
		vector<P> Data;
		for(int i = 0; i < m; ++i)
		{
			string s;
			getline(cin, s);
			string temp;
			for(int j = 0; j < s.size(); ++j)
			{
				if('0' <= s[j] && s[j] <= '9')
				{
					temp += s[j];
				}
				else
				{
					stringstream ss;
					int d;
					ss << temp;
					ss >> d;
					Point[i].push_back(d);
					temp = "";
				}
			}
			stringstream ss;
			int d;
			ss << temp;
			ss >> d;
			Point[i].push_back(d);
			Point[i].push_back(0);
			Point[i].push_back(0);

			int sum = 0;
			int strike = 0;
			bool spare = false;
			bool first = true;
			int frame = 1;
			for(int j = 1; j < Point[i].size() - 2; ++j)
			{
				if(Point[i][j] == 10)
				{
					strike = 2;
					sum += 10 + Point[i][j + 1] + Point[i][j + 2];
				}
				else if(Point[i][j] + Point[i][j + 1] == 10)
				{
					spare = true;
					sum += 10 + Point[i][j + 2];
					++j;
				}
				else
				{
					sum += Point[i][j] + Point[i][j + 1];
					++j;
				}
				++frame;
				if(frame == 11)
				{
					break;
				}
			}
			P p;
			p.first = -sum;
			p.second = Point[i][0];
			Data.push_back(p);
		}
		sort(Data.begin(), Data.end());
		for(int i = 0; i < Data.size(); ++i)
		{
			cout << Data[i].second << " " << -Data[i].first << endl;
		}
	}
}

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

C++: #include <stdio.h>
int main(void)
{
	int n,scar,a,i,j=1,vox[256][256]={0},flag=1,dflag=0,c;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%d",&a);
			vox[i][0]=a;
			while(flag!=0){
				scanf("%d",&scar);
				vox[i][j]=scar;
				if(vox[i][j]==10){
					dflag=dflag+2;
				}
				else{
					dflag++;
				}
				if(dflag==20){
					if(vox[i][j]==10){
						scanf("%d",&scar);
						vox[i][j+1]=scar;
						scanf("%d",&scar);
						vox[i][j+2]=scar;
						flag=0;
					}
					else if(vox[i][j]+vox[i][j-1]==10){
						scanf("%d",&scar);
						vox[i][j+1]=scar;
						flag=0;
					}
					else{
						flag=0;
					}
				}
				j++;
			}
			j=1;
			flag=1;
			dflag=0;
		}
		/*for(i=0;i<n;i++){
			}
			printf("\n");
		}*/
		a=1;
		for(i=0;i<n;i++){
			for(j=1;j<21;j=j+2){
				if(vox[i][j]==10&&a<10){
					vox[i][30]=vox[i][30]+vox[i][j+1]+vox[i][j+2];
					j=j-1;
					a++;
				}
				else if(vox[i][j]+vox[i][j+1]==10){
					vox[i][30]=vox[i][30]+vox[i][j+2];
					a++;
				}
				else{
					a++;
				}
			}
			a=1;
		}
		for(i=0;i<n;i++){
			for(j=1;j<21;j++){
				vox[i][30]=vox[i][30]+vox[i][j];
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(vox[j][30]<vox[j+1][30]){
					c=vox[j][30];
					vox[j][30]=vox[j+1][30];
					vox[j+1][30]=c;
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%d %d\n",vox[i][0],vox[i][30]);
		}
		for(i=0;i<200;i++){
			for(j=0;j<200;j++){
				vox[i][j]=0;
			}
		}
		j=1;
		scanf("%d",&n);
	}
	return 0;
}