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<stdio.h>
#include<string.h>
#include<math.h>
int a,s[100],d[100][30],f,g[100],h,j,i,k,z[100][30],x[100][30],c,q[100];
int aa[100][30],ss;
int main(void)
{
	while(1){
		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<12;j++){
				printf("%d ",aa[i][j]);
			}
			printf("\n");
		}*/
		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]];
				//	printf("1  %d\n",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 <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    while(cin >> n, n){
        cin.ignore();
        vector<pair<int, int> > ans;
        for(int i=0; i< n; i++){
            string ss;
            getline(cin,ss);

            vector<int> v;
            while(true){
                int idx = 0;
                while(ss[idx] != ' ') idx++;
                string num = ss.substr(0, idx);
                v.push_back(stoi(num));
                if(num == ss) break;
                ss = ss.substr(idx+1);
            }
            pair<int, int> p;
            p.second = -1*v[0];
            int score = 0;
            int frame[15] = {0};
            int s[15] = {0};
            int pp[15] = {0};
            int count = 0;
            for(int i=1; i< v.size(); i++){
                if(count < 9){
                    int pin = v[i];
                    if(pin != 10){
                        i++;
                        pin += v[i];
                        if(pin == 10) s[count] = 2;
                        else s[count] = 1;
                        frame[count] = pin;
                    }
                    else {
                        s[count] = 3;
                        frame[count] = pin;
                    }
                } else {
                    int pin = v[i];
                    s[count] = 1;
                    frame[count] = pin;
                }
                pp[count] = i;
                count++;
            }
            for(int i=0; i < 12; i++){
                score += frame[i];
                for(int j=1; j < s[i]; j++){
                    score += v[pp[i]+j];
                }
            }
            p.first = score;
            ans.push_back(p);
        }
        sort(ans.rbegin(), ans.rend());
        for(int i=0; i < ans.size(); i++){
            cout << -ans[i].second << " " << ans[i].first << endl;
        }
    }
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;

int calc(int a[21]) {
  bool spare[10] = {false};
  bool strike[10] = {false};
  int s = 0, p = 0;
  for (int i=0; i<10; i++) {
    s += a[p];
    if (i>0 && (spare[i-1] || strike[i-1])) {
      s += a[p];
    }
    if (p>1 && i>1 && strike[i-1] && strike[i-2]) {
      s += a[p];
    }
    if (a[p] == 10) {
      strike[i] = true;
      p++;
      continue;
    }
    s += a[p+1];
    if (i>0 && strike[i-1]) {
      s += a[p+1];
    }
    if (a[p] + a[p+1] == 10) {
      spare[i] = true;
    }
    p += 2;
  }
  if (spare[9]) {
    s += a[p];
  } else if (strike[9]) {
    s += a[p] + a[p+1];
    if (strike[8]) {
      s += a[p];
    }
  }
  return s;
}


int main() {
  int a[21];
  pair<int,int> s[40];
  int n, m, p, c;
  char buf[100];
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      fgets(buf, sizeof(buf), stdin);
      p = 0;
      sscanf(buf, "%d%n", &s[i].second, &c);
      p += c;
      m = 0;
      while (1) {
        if (sscanf(buf+p, "%d%n", &a[m], &c) != 1) break;
        ++m;
        p += c;
      }
      s[i].first = calc(a);
    }
    sort(s, s+n);
    for (int i=n-1; i>=0; i--) {
      printf("%d %d\n", s[i].second, s[i].first);
    }
  }
  return 0;
}