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 <cstdio>
#define INITIAL 0
using namespace std;
struct IDSCORE {
int ID;
int SCORE;
};
int BOWLINGSCORE(int h[22]){
int NEXT=INITIAL,total=INITIAL;
if (h[1]<10){    //1
    total+=h[1]+h[2];
    if (h[1]+h[2]==10){
        total+=h[3];
    }
NEXT=3;
}
else {
    total+=h[1]+h[2]+h[3];
    NEXT=2;
}
if (h[NEXT]<10){ //2
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //3
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //4
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //5
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //6
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //7
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //8
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //9
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
NEXT+=2;
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
    NEXT+=1;
}
if (h[NEXT]<10){ //10
    total+=h[NEXT]+h[NEXT+1];
    if (h[NEXT]+h[NEXT+1]==10){
        total+=h[NEXT+2];
    }
}
else {
    total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
}
return total;
}
int main (){
IDSCORE ret[64];
int m,n[1+21],ct[1+21],b=0,s=0,o=0;
while (1){
cin>>m;
if (m==0)break;
///////////////////////////////////////////////////////
for (int i=0;i<m;i++){
    for (int zzz=0;zzz<22;zzz++){
        n[zzz]=0;
        ct[zzz]=0;
    }
    b=0;
    s=0;
    o=0;
    cin>>n[0]; //score
    for (int j=1;j<19;j=j+2){
        cin>>n[j];
        if (n[j]==10) n[j+1]=11;
        else cin>>n[j+1];
    }
    cin>>n[19];
    cin>>n[20];
    if (n[19]+n[20]>=10)cin>>n[21];

    for (int j=0;j<22;j++){
        if (n[j]!=11){
            ct[b]=n[j];
            b++;
        }
    }

ret[i].SCORE=BOWLINGSCORE(ct);
ret[i].ID=n[0];
}
//////////////////////////////////////////////////////
for (int i=0;i<m-1;i++){
    for (int j=i+1;j<m;j++){
        if (ret[i].SCORE<ret[j].SCORE){
        IDSCORE temp=ret[i];
        ret[i]=ret[j];
        ret[j]=temp;
        }
    }
}
while (1){
    if (s==m+1){
        s=0;
        if (o==0)break;
        else o=0;
    }
if (ret[s].SCORE==ret[s+1].SCORE&&ret[s].ID>ret[s+1].ID){
    IDSCORE temp=ret[s];
    ret[s]=ret[s+1];
    ret[s+1]=temp;
    o++;
}
s++;
}
for (int i=0;i<m;i++){
    cout<<ret[i].ID<<" "<<ret[i].SCORE<<endl;
}
}
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
int n;
int main(void)
{
  while(cin >> n && n)
    {
      set<int> st;
      st.clear();
      vector<pii> scores(10005);
      for(int i=0;i<=10000;i++)
	{
	  scores[i]=(pii(0,i));
	}
      vector<pair<int,int> > bowling[10005];
      for(int i=0;i<n;i++)
	{
	  //cout << "ID"<< endl;
	  int id;
	  cin >> id;
	  st.insert(id);
	  for(int j=0;j<10;j++)
	    {
	      
	      int fi=0,se=0,th=0;
	      cin >> fi;
	      if(j!=9 && fi==10) se=0;
	      else
		{
		  cin >> se;
		}
	      if(j==9 && ((fi==10) || (fi+se)==10))
		{
		  cin >> th;
		}
	      if(j!=9) bowling[id].push_back(pii(fi,se));
	      else 
		{
		  bowling[id].push_back(pii(fi,se));
		  scores[id].first+=(fi+se+th);
		}
	    }
	  for(int j=0;j<9;j++)
	    {
	      if(j!=8)
		{
		  int one=bowling[id][j].first;
		  int two=bowling[id][j].second;
		  int nxone=bowling[id][j+1].first;
		  int nxtwo=bowling[id][j+1].second;
		  int nxxone=bowling[id][j+2].first;
		  if(one+two<10)
		    {
		      scores[id].first+=(one+two);
		    }
		  else if(one!=10 && one+two==10)
		    {
		      scores[id].first+=(10+nxone);
		    }
		  else if(one==10)
		    {
		      if(nxone!=10)
			{
			  scores[id].first+=(10+nxone+nxtwo);
			}
		      else if(nxone==10)
			{
			  if(j<=8)
			    {
			      scores[id].first+=(10+nxone+nxxone);
			    }
			}
		    }
		}
	      else if(j==8)
		{
		  int one=bowling[id][j].first;
		  int two=bowling[id][j].second;
		  int nxone=bowling[id][j+1].first;
		  int nxtwo=bowling[id][j+1].second;
		  if(one+two<10)
		    {
		      scores[id].first+=(one+two);
		    }
		  else if(one!=10 && one+two==10)
		    {
		      scores[id].first+=(10+nxone);
		    }
		  else if(one==10)
		    {
		      if(nxone!=10)
			{
			  scores[id].first+=(10+nxone+nxtwo);
			}
		      else if(nxone==10)
			{
			  scores[id].first+=(10+nxone+nxtwo);
			}
		    }
		}
	      //cout << "Now ID score " << scores[i].second << ' ' << scores[id].first << endl;
	    }
	}
      sort(scores.begin(),scores.end(),greater<pair<int,int> > ());
      int cnt=0;
      for(int i=0;i<=10000;i++)
	{
	  if(cnt==n) break;
	  auto it=st.find(scores[i].second);
	  if(it!=st.end())
	    {
	      cnt++;
	      cout << scores[i].second << ' ' << scores[i].first << endl;
	    }
	}
    }
  return 0;
}