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<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int i,j,k;
	int a,s[100],d[100][30],f,g[100],h,z[100][30],x[100][30],c,q[100];
	int aa[100][30],ss;
	while(1){
		f=0;
		h=0;
		c=0;
		ss=0;
		h=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<99;i++){
			s[i]=0;
			g[i]=0;
			q[i]=0;
			for(j=0;j<21;j++){
				d[i][j]=0;
				aa[i][j]=0;
				z[i][j]=0;
				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<algorithm>
#include<string>
using namespace std;
pair<int,int> d[40];
int cnt,sparecnt,throwcnt;
int plusser[2];
int numcnt;
void Sc(int u){
	if(numcnt>9)plusser[0]--;
	if(numcnt>10)plusser[0]--;
	d[u].first+=cnt*plusser[0];
	plusser[0]=plusser[1];
	plusser[1]=1;
	throwcnt++;
	sparecnt+=cnt;
	if(throwcnt==2){
		if(sparecnt==10){
			plusser[0]++;
		}
		throwcnt=0;
		sparecnt=0;
		numcnt++;
	}
	if(cnt==10){
		plusser[0]++;
		plusser[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;
		plusser[0]=1,plusser[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++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
#include<sstream>
using namespace std;
typedef long long ll;

struct Data
{
	int score, num;
	bool operator < (const Data a) const
	{
		return (score == a.score) ? num < a.num : score > a.score;
	}
};

int main(){
	int M;
	while(cin >> M, M)
	{
		Data s[40];
		for(int i = 0; i < M; i++)
		{
			cin >> s[i].num;
			s[i].score = 0;
			queue<int> latte;

			for(int j = 1; j <= 10; j++)
			{
				int pin[2] = {};
				for(int k = 0; k < 2; k++)
				{
					cin >> pin[k];
					int size = latte.size();
					for(int l = 0; l < size; l++)
					{
						if(latte.front() == 2) latte.push(1);
						latte.pop();
						s[i].score += pin[k];
					}
					if(j < 10 && pin[k] == 10) break;
				}
				s[i].score += pin[0] + pin[1];
				if(j == 10 && pin[0] + pin[1] >= 10)
				{
					cin >> pin[0];
					s[i].score += pin[0];
				}
				if(j == 10) break;
				if(pin[0] == 10) latte.push(2);
				else if(pin[0] + pin[1] == 10) latte.push(1);
			}
		}
		sort(s, s + M);
		for(int i = 0; i < M; i++)
		{
			printf("%d %d\n", s[i].num, s[i].score);
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(cin>>n&&n){
		vector<pair<int,int> >dat;
		while(n--){
			int mem;
			cin>>mem;
			vector<int> scr;
			int a,b,c;
			for(int i=0;i<10;i++){
				cin>>a;
				scr.PB(a);
				if(a!=10||i==9){
					cin>>b;
					scr.PB(b);
				}else continue;
				if(i==9&&(a+b==10||a==10)){
					cin>>c;
					scr.PB(c);
				}else continue;
			}
			int ans=0,k=0;
			for(int i=0;i<9;i++){
				if(scr[k]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k++;
					continue;
				}
				if(scr[k]+scr[k+1]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k+=2;
					continue;
				}
				ans+=scr[k]+scr[k+1];
				k+=2;
			}
			while(k<scr.size())ans+=scr[k++];
			dat.PB(MP((-1)*ans,mem));
		}
		sort(dat.begin(),dat.end());
		for(int i=0;i<dat.size();i++){
			cout<<dat[i].second<<" "<<dat[i].first*(-1)<<endl;
		}
	}
}