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 <iostream>
#include <cstdlib>

using namespace std;

struct player{
  int id;
  int sc;
};

void func(player a[], int n)
{
  player t;
  for(int i = n-1; i >= 0; i--){
    for(int j = 1; j <= i; j++){
      if(a[j].sc > a[j-1].sc){
	t = a[j];
	a[j] = a[j-1];
	a[j-1] = t;
      }
    }
  }

  return ;
}


int main(int argc, char **argv)
{
  int n, s, t, u, *a;
  player pl[40];

  while(1){
    cin >> n;
    if(n == 0){
      break;
    }
    for(int j = 0; j < n; j++){
      cin >> pl[j].id;
      a = (int *)calloc(10, sizeof(int));
      pl[j].sc = 0;
      for(int i = 0; i < 9; i++){
	cin >> s;
	for(int k = 0; k < i; k++){
	  if(a[k] > 0){
	    a[k]--;
	    pl[j].sc += s;
	  }
	}
	if(s == 10){
	  a[i] = 2;
	  t = 0;
	} else {
	  cin >> t;
	  for(int k = 0; k < i; k++){
	    if(a[k] > 0){
	      a[k]--;
	      pl[j].sc += t;
	    }
	  }
	  if(s+t == 10){
	    a[i] = 1;
	  }
	}
	pl[j].sc += (s+t);
      }
      cin >> s >> t;
      if(s+t >= 10){
	cin >> u;
      } else {
	u = 0;
      }
      pl[j].sc += (s+t+u);
      for(int k = 7; k < 9; k++){
	if(a[k] > 0){
	  a[k]--;
	    pl[j].sc += s;
	}
	if(a[k] > 0){
	  a[k]--;
	  pl[j].sc += t;
	}
      }
      free(a);
    }
    func(pl, n);
    for(int i = 0; i < n; i++){
      cout << pl[i].id << " " << pl[i].sc << 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 && 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;
}

bool compare(const pair<int, int> &l, const pair<int, int> &r) {
  if (l.first < r.first) {
    return true;
  } else if (l.first > r.first) {
    return false;
  } else if (l.second > r.second) {
    return true;
  } else {
    return false;
  }
}

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, compare);
    for (int i=n-1; i>=0; i--) {
      printf("%d %d\n", s[i].second, s[i].first);
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <queue>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		priority_queue<P> pq;
		for (int i = 0; i < n; i++) {
			P p;
			cin >> p.second;
			vector<int> hyou(21, 0);
			int a;
			for (int j = 0; j < 10; j++) {
				cin >> a;
				if (j != 9) {
					if (a == 10) {
						hyou[j*2] = a;
						hyou[j*2+1] = -1;
					} else {
						hyou[j*2] = a;
						cin >> hyou[j*2+1];
					}
				} else {
					if (a == 10) {
						hyou[j*2] = a;
						cin >> hyou[j*2+1] >> hyou[j*2+2];
					} else {
						hyou[j*2] = a;
						cin >> hyou[j*2+1];
						if (a+hyou[j*2+1] == 10) {
							cin >> hyou[j*2+2];
						}
					}
				}
			}
			p.first = 0;
			for (int j = 0; j < 9; j++) {
				p.first += hyou[j*2];
				if (hyou[j*2] == 10) {
					p.first += hyou[j*2+2];
					if (hyou[j*2+3] == -1) {
						p.first += hyou[j*2+4];
					} else {
						p.first += hyou[j*2+3];
					}
				} else {
					p.first += hyou[j*2+1];
					if (hyou[j*2]+hyou[j*2+1] == 10) {
						p.first += hyou[j*2+2];
					}
				}
			}
			p.first += hyou[18]+hyou[19]+hyou[20];
			pq.push(p);
		}
		while (!pq.empty()) {
			P pp = pq.top();
			pq.pop();
			stack<int> str;
			str.push(pp.second);
			while (!pq.empty() && (pq.top()).first == pp.first) {
				str.push((pq.top()).second);
				pq.pop();
			}
			while (!str.empty()) {
				cout << str.top() << ' ' << pp.first << endl;
				str.pop();
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
using namespace std;

int calc(vector<int> v) {
	v.push_back(0);
	int ret = 0;
	int k = 0, p1, p2, p3;
	for (int i=0; i<10; ++i) {
		p1 = 0, p2 = 0, p3 = 0;
		p1 = v[k++];
		if (i == 9) {
			p2 = v[k++];
			if (p1 == 10 || p1 + p2 == 10) p3 = v[k++];
		} else {
			if (p1 == 10) {
				ret += v[k] + v[k+1];
			} else {
				p2 = v[k++];
				if (p1 + p2 == 10) {
					ret += v[k];
				}
			}
		}
		ret += p1 + p2 + p3;
	}
	return ret;
}

int main() {
	int m;
	while (cin >> m, m) {
		cin.ignore();
		vector<pair<int,int>> res;
		string s;
		int idx, t;
		for (int i=0; i<m; ++i) {
			getline(cin, s);
			stringstream ss(s);
			ss >> idx;
			vector<int> score;
			while (ss >> t) {
				score.push_back(t);
			}
			res.push_back(make_pair(-calc(score), idx));
		}
		sort(res.begin(), res.end());
		for (int i=0; i<(int)res.size(); ++i) {
			cout << res[i].second << " " << -res[i].first << endl;
		}
	}
	return 0;
}