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 <stack>
#include <math.h>

using namespace std;

struct Student{
	int id,score;
};

struct Data{
	int score,first,second;
	bool strike,spare;
};

int main(){

	int num,tmp,index,pre_score;
	char buf[120];
	Student students[40];
	Data game_data[12];
	bool First;

	while(true){
		scanf("%d",&num);
		if(num == 0)break;

		for(int i = 0; i < 40; i++){
			students[i].score = 0;
		}

		getchar();

		for(int i = 0; i < num; i++){
			for(int k=0; k <= 12; k++){
				game_data[k].score = 0;
				game_data[k].first = 0;
				game_data[k].second = 0;
				game_data[k].strike = false;
				game_data[k].spare = false;
			}

			First = true;

			fgets(buf,120,stdin);

			tmp = 0;
			index = 0;
			pre_score = -1;
			for(int k = 0; buf[k] != '\n'; k++){
				if(buf[k] >= '0' && buf[k] <= '9'){
					tmp = 10*tmp + (buf[k] - '0');

					if(buf[k+1] == '\n'){
						if(pre_score == -1){
							game_data[index].first = tmp;
							game_data[index].score = tmp;
						}else{
							game_data[index].second = tmp;
							game_data[index].score = pre_score + tmp;
						}
					}
				}else{
					if(First){
						students[i].id = tmp;
						First = false;
					}else{

						if(pre_score == -1){
							game_data[index].first = tmp;
							if(tmp == 10){
								game_data[index].score = 10;
								game_data[index].strike = true;
								index++;
							}else{
								pre_score = tmp;
							}

						}else{
							game_data[index].second = tmp;
							game_data[index].score = pre_score + tmp;
							if(pre_score + tmp == 10){
								game_data[index].spare = true;
							}

							index++;

							pre_score = -1;
						}
					}

					tmp = 0;
				}
			}

			for(int k = 0; k <= 11; k++){
				students[i].score += game_data[k].score;
					if(k <= 8 && game_data[k].spare == true){
					students[i].score += game_data[k+1].first;
				}

				if(k <= 8 && game_data[k].strike == true){
					students[i].score += game_data[k+1].first;
					if(game_data[k+1].first == 10){
						students[i].score += game_data[k+2].first;
					}else{
						students[i].score += game_data[k+1].second;
					}
				}
			}
		}

		for(int i = 1; i <= num-1; i++){
			for(int k = num-1; k >= i; k--){
				if(students[k].score > students[k-1].score)swap(students[k],students[k-1]);
				else if(students[k].score == students[k-1].score && students[k].id < students[k-1].id)swap(students[k],students[k-1]);
			}
		}

		for(int i=0; i < num; i++){
			printf("%d %d\n",students[i].id,students[i].score);
		}
	}

    return 0;
}

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 && 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 (a[p] == 10) {
      s += a[p+1];
    }
  }
  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;
}

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) {
				buf >> s[f][b];
				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);
		}
	}
}