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 <bits/stdc++.h>
using namespace std;

int main(void){
    // Your code here!
    while (true){
    int n,d=1,u=1,m=0,t=0,a,b;
    cin >> n;
    if (n==0) break;
    vector<int> id(n),s(n),dd(100000);
    for (int i=0;i<100000;i++){
        dd.at(i)=1;
    }
    for (int i=0;i<n;i++){
        cin >> id.at(i);
        t=0;u=1;m=0;d+=3;
        while (true){
            if (u<10){
            cin >> a;
            t=t+a;
            if (m==0 && t<10) {m++;d++;continue;}
            else if (t<10) {s.at(i)+=(t-a)*dd.at(d-1);s.at(i)+=a*dd.at(d);d++;t=0;u++;m=0;}
            else if (m==0 && t==10) {s.at(i)+=t*dd.at(d);dd.at(d+1)++;dd.at(d+2)++;t=0;u++;m=0;d++;}
            else {s.at(i)+=(t-a)*dd.at(d-1);s.at(i)+=a*dd.at(d);dd.at(d+1)++;t=0;u++;m=0;d++;}
            }
            if (u==10){
                cin >> a >> b;
                if (a+b>=10) {s.at(i)+=a*dd.at(d);s.at(i)+=b*dd.at(d+1);cin >> a;s.at(i)+=a;}
                else {s.at(i)+=a*dd.at(d);s.at(i)+=b*dd.at(d+1);}
                break;
            }
        }
    }
    vector<pair<int,int>> v(n);
    for (int i=0;i<n;i++){
        v.at(i).second=s.at(i);
        v.at(i).first=id.at(i);
    }
    sort(v.begin(),v.end(), [&](const pair<int, int>& x, const pair<int, int>& y) {
			if (x.second == y.second) {
				return x.first < y.first;
			}
			return x.second > y.second;
		});
    for (int i=0;i<n;i++) {
			cout << v[i].first << " " << v[i].second << endl;
		}
}
}

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

int main(){
  int n;
  int m[40];
  int s[40];
  int p[21],d[21];
  int f,tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++){
      cin >> m[i];
      s[i] = 0;
      for(int j=0;j<21;j++)p[j] = 0;
      for(int j=0;j<21;j++)d[j] = 1;
      f = 0;
      while(1){
	cin >> tmp;
	if(f<18){
	  if(!(f%2) && tmp==10){
	    p[f] = 10;
	    f+=2;
	  }else{
	    p[f] = tmp;
	    f++;
	  }
	}else{
	  if(f==18){
	    p[f] = tmp;
	    f++;
	  }else if(f==19){
	    p[f] = tmp;
	    if(p[f-1]+p[f] > 9){
	      cin >> tmp;
	      p[f+1] = tmp;
	    }
	    break;
	  }
	}
      }
     
      for(int j=0;j<18;j++){
	if(!(j%2) && p[j]==10){
	  d[j+2]++;
	  if(p[j+2]==10 && j+2 != 18)d[j+4]++;
	  else d[j+3]++;
	}else if(p[j] && j%2 && p[j-1]+p[j]==10){
	  d[j+1]++;
	}
      }
      
      for(int j=0;j<21;j++){
	s[i]+=d[j]*p[j];
      }
    }

    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	if(s[i]<s[j]){
	  swap(s[i],s[j]);
	  swap(m[i],m[j]);
	}else if(s[i]==s[j] && m[i]>m[j]){
	  swap(s[i],s[j]);
	  swap(m[i],m[j]); 
	}
      }
    }

    for(int i=0;i<n;i++){
      cout << m[i] << " " << s[i] << endl;
    }
  }
}

C++: #include <iostream>
#include <string>
#include <iostream>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<int, string> Ps;

Ps data[40];
int cnt[11];
int main(){
  int m, a, b, c, score;
  while(cin >> m && m){
    rep(i, m){
      score = 0;

      fill(cnt, cnt + 10, 0);
      cin >> data[i].second;
      rep(j, 10){
	cin >> a;
	score += a;
	rep(k, 10) if(cnt[k] > 0){
	  cnt[k]--;
	  score += a;
	}

	if(a == 10){

	  if(j != 9)cnt[j]+=2;
	  else{
	    cin >> b >> c;
	    score += b + c;
	    rep(k, 10)if(cnt[k]){
	      cnt[k]--;
	      score += b;
	    }
	  }
	  
	}else{

	  cin >> b;
	  score += b;
	  rep(k, 10) if(cnt[k] > 0){
	    cnt[k]--;
	    score += b;
	  }
	  if(a + b == 10){
	    if(j != 9)cnt[j]++;
	    else{
	      cin >> c;
	      score += c;
	    }
	  }
	}
      }
      data[i].first = -score;
    }
    sort(data, data + m);
    rep(i, m){
      cout << data[i].second << " " << -data[i].first << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <sstream>
#include <map>
#include <set>
using namespace std;
int point(vector<int>& v)
{
  int id = 0,pt = 0;
  for(int i=0; i<9; i++){
    if(v[id] == 10){
      pt += 10 + v[id+1] + v[id+2];
      id++;
    }else if(v[id] + v[id+1] == 10){
      pt += 10 + v[id+2];
      id += 2;
    }else{
      pt += v[id] + v[id+1];
      id += 2;
    }
  }
  while(id < v.size()){
    pt += v[id++];
  }
  return pt;
}
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    map<int,set<int> > ma;
    for(int i=0; i<n; i++){
      int num;
      cin >> num;
      string s;
      getline(cin,s);
      stringstream str(s);
      vector<int> v;
      while(!str.eof()){
        int j;
        str >> j;
        v.push_back(j);
        str.ignore();
      }
      ma[point(v)].insert(num);
    }
    for(map<int,set<int> >::reverse_iterator r=ma.rbegin(); r!=ma.rend(); r++){
      int pt = (*r).first;
      set<int> s = (*r).second;
      for(set<int>::iterator it=s.begin(); it!=s.end(); it++){
        cout << *it << " " << pt << endl;
      }
    }
  }
  return 0;
}