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 <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<pair<int, int> > v;
		
		for (int i = 0; i < n; i++){
			int stNo;
			scanf("%d", &stNo);
			
			int frame = 0;
			int frameScore[10] = {0}, remain[10] = {0};
			int prev = -1;
			int ct = 0;
			while (frame < 10){
				int pin;
				scanf("%d", &pin);
				frameScore[frame] += pin;
				
				if (frame == 9){
					if (ct == 1 && frameScore[frame] < 10) frame++;
					else if (ct == 2) frame++;
					ct++;
				}
				
				for (int j = 0; j < 10; j++){
					if (remain[j]){
						frameScore[j] += pin;
						remain[j]--;
					}
				}
				if (frame < 9){
					if (pin == 10){
						remain[frame] = 2;
						frame++;
						prev = -1;
					}
					else if (prev + pin == 10){
						remain[frame] = 1;
						frame++;
						prev = -1;
					}
					else if (~prev){
						frame++;
						prev = -1;
					}
					else prev = pin;
				}
			}
			
			int sum = 0;
			for (int j = 0; j < 10; j++) sum += frameScore[j];
			v.push_back(make_pair(sum, stNo));
		}
		
		sort(v.rbegin(), v.rend());
		for (int i = 0; i < n; i++){
			printf("%d %d\n", v[i].second, v[i].first);
		}
	}
	
	return (0);
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
namespace std {
  bool operator < (const P& a, const P& b) { return a.second != b.second ? a.second > b.second : a.first < b.first; }
}

vector<int> split(string &str, char delim){
  stringstream ss(str);
  string tmp;
  vector<int> res;
  while(getline(ss, tmp, delim)) res.push_back(atoi(tmp.c_str()));
  return res;
}

int solve(vector<int> v){
  int t = 1, i = 1, res = 0;
  while(i < v.size()){
    if(t >= 10){
      res += v[i++];
    } else if(v[i] >= 10){
      res += v[i] + v[i + 1] + v[i + 2];
      ++i;
      ++t;
    } else if(v[i] + v[i + 1] >= 10){
      res += v[i] + v[i + 1] + v[i + 2];
      i += 2;
      ++t;
    } else{
      res += v[i] + v[i + 1];
      i += 2;
      ++t;
    }
  }
  return res;
}

int main() {
  int N;
  while(cin >>N && N){
    vector<P> ps(N);
    string s; getline(cin, s);
    REP(i, N){
      getline(cin, s);
      vector<int> v = split(s, ' ');
      ps[i] = P(v[0], solve(v));
    }
    SORT(ps);
    REP(i, ps.size()) cout <<ps[i].first <<" " <<ps[i].second <<endl;
  }
  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 (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;
}

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[10][5];

P operator+(P a, int d) {
	rep(i, d) {
		if (~s[a.first][a.second + 1])a.second++;
		else {
			a.first++; a.second = 0;
		}
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			int id; scanf("%d", &id);
			int f = 0, cnt = 0;
			while (f < 9) {
				scanf("%d", &s[f][cnt]);
				if (s[f][cnt] == 10)f++;
				else if (cnt) {
					f++; cnt = 0;
				}
				else cnt++;
			}
			scanf("%d%d", &s[9][0], &s[9][1]);
			if (s[9][0] + s[9][1] >= 10)scanf("%d", &s[9][2]);
			P p(0, 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;
			}
			cnt = 0;
			rep(i, 10)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);
		}
	}
}