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

using namespace std;

int calcscore()
{
	int score=0,strike=0,spare=0,pin[2];

	for(int i=1;i<=9;i++){
		for(int j=0;j<2;j++){
			if(j==1 && pin[0]==10)	continue;
			cin>>pin[j];
			if(strike>0)	score+=(strike%10)*pin[j],strike/=10;
			if(spare>0)		score+=pin[j],spare--;
			score+=pin[j];
			if(j==1)	pin[j]+=pin[j-1];
			if(pin[j]==10){
				if(j==0)	strike+=11;
				if(j==1)	spare++;
			}
		}
	}

	for(int i=0;i<2;i++){
		cin>>pin[i];
		if(strike>0)	score+=(strike%10)*pin[i],strike/=10;
		if(spare>0)		score+=pin[i],spare--;
		score+=pin[i];
	}
	if(pin[0]+pin[1]>=10){
		cin>>pin[0];
		score+=pin[0];
	}

	return score;
}

int main()
{
	for(int m;cin>>m,m;){
		vector< pair<int,int> > data(m);
		for(int i=0;i<m;i++){
			int id;	cin>>id;
			data[i]=make_pair(-calcscore(),id);
		}
		sort(data.begin(),data.end());
		for(int i=0;i<m;i++)
			cout<<data[i].second<<' '<<-data[i].first<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair <int,int> P;
int main(){
  int n;
  while(cin>>n,n){
  vector <P> ans;
  while(n--){
    int ID,sum=0,cnt=0,ste[2]={},cnt2=0,pre=0,a,cnt3=0;
    cin>>ID;
    while(cnt<10){
      cin>>a;
      cnt3++;
      cnt2++;
      while(ste[cnt3%2])sum+=a,ste[cnt3%2]--;
      if(cnt2==1&&a==10) ste[cnt3%2]++,ste[(cnt3+1)%2]++,cnt2=2;
      else if(cnt2==2&&a+pre==10) ste[(cnt3+1)%2]++;
      pre=a;
      if(cnt2==2) cnt++,cnt2=0,pre=0;
      sum+=a;
    }

    if(ste[0]) cin>>a;
    while(ste[0]--)sum+=a;
    if(ste[1]) cin>>a;
    while(ste[1]--)sum+=a;
    ans.push_back(P(sum,ID));
  }
  sort(ans.begin(),ans.end());
  for(int i=(int)ans.size()-1;i>=0;i--) cout << ans[i].second<<" "<<ans[i].first<<endl;
  }
  return 0;
}

C++: 

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,m,score[42][22],id[42],x,cnt,yoso[42],sum[42],flg[42][22],p,check[42];
	
	while(1) {
		cin>>m;
		if(m==0) break;
		for(i=0;i<m;i++) yoso[i]=sum[i]=check[i]=0;
		for(i=0;i<m;i++) {
			cnt=21;
			cin>>id[i];
			x=p=0;
			for(j=0;j<21;j++) flg[i][j]=-1;
			while(cnt>0) {
				cin>>score[i][x];
				if(cnt<=3) {
					if(score[i][x]==10) cnt--,flg[i][x]=2;
					else if(cnt==1&&score[i][x]+score[i][x-1]==10) flg[i][x]=flg[i][x-1]=1;
					else cnt-=2,flg[i][x]=0;
				}	
				else {
					if(score[i][x]==10) cnt-=2,flg[i][x]=2;
					else if(p==1&&score[i][x]+score[i][x-1]==10) flg[i][x]=flg[i][x-1]=1,p=0,cnt--;
					else if(p==1) cnt--,flg[i][x]=0,p=0;
					else cnt--,flg[i][x]=0,p=1;
				}
				x++;
			}
			yoso[i]=x;
		}
		int a;
		for(i=0;i<m;i++) {
			a=0;
			for(j=0;j<yoso[i];j++) {
				if(a!=9) {
					if(flg[i][j]!=2) j++,a++;
					else a++;
				}
				else check[i]++;
			}
		}
		for(i=0;i<m;i++) {
			for(j=0;j<yoso[i];j++) {
				if(j<yoso[i]-check[i]) {
					if(flg[i][j]==0) sum[i]+=score[i][j]+score[i][j+1],j++;
					else if(flg[i][j]==1) {
						sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
						j++;
					}
					else sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
				}
				else {
					if(check[i]==3) sum[i]+=score[i][j]+score[i][j+1]+score[i][j+2];
					else sum[i]+=score[i][j]+score[i][j+1];
					break;
				}
			}
		}
		for(i=0;i<m-1;i++) {
			for(j=i+1;j<m;j++) {
				if(sum[i]<sum[j]) swap(sum[i],sum[j]),swap(id[i],id[j]);
				if(sum[i]==sum[j]&&id[i]>id[j]) swap(id[i],id[j]); 
			}
		}
		for(i=0;i<m;i++) cout<<id[i]<<" "<<sum[i]<<endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    vector<P> a;
    a.resize(n+1);
    string s;
    getline(cin,s);
    for(int j=0; j<n; j++) {
      getline(cin,s);
      stringstream ss;
      ss << s;
      ss >> a[j].second;
      a[j].second*=-1;
      a[j].first=0;
      vector<int> b;
      int x;
      while(ss >> x) b.push_back(x);
      int i=0,k=0;
      vector<int> c;
      c.resize(b.size()+1);
      fill(c.begin(),c.end(),0);
      while(i<b.size()) {
        k++;
        a[j].first+=b[i];
        if(i&&c[i-1]) a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i]==10) {
          if(k<10)c[i]=2;
          i++;
          continue;
        }
        i++;
        if(i>=b.size()) break;
        a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i-1]+b[i]==10) {
          if(k<10)c[i]=1;
          i++;
          continue;
        }
        i++;
        if(i>=b.size()) break;
        if(k==10) {
          a[j].first+=b[i];
          i++;
        }
      }
    }
    sort(a.rbegin(),a.rend());
    for(int i=0; i<n; i++) cout << a[i].second << " " << -a[i].first << endl;
  }
  return 0;
}