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 <iostream>
#include <sstream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

bool compare(const pair<int,int> &a,const pair<int,int> &b){
	if(a.second!=b.second) return a.second>b.second;
	else return a.first<b.first;
}

int main(void){
  int m;
  while(cin>>m,m){
  	cin.ignore();
    vector<pair<int,int> > score;
    for(int x=0;x<m;++x){
	    int num,f=0,t=0,sc=0,flag=0;
	    vector<int> bonus(21,1);
	    string s;
	    getline(cin,s);
	    stringstream ss;
	    ss<<s;
	    ss>>num;
	    while(!ss.eof()&&f<10){
	      int a,b;
	      ss>>a;
	      sc+=a*bonus[t];
	      if(a==10){
	      	if(f==9)flag=1;
	      	if(f!=9){
			      ++bonus[t+1];
			      ++bonus[t+2];
		      }
		      ++t;
		      if(f==9&&flag){
		      	ss>>a;
		      	sc+=a*bonus[t];
		      	++t;
		      }
	      }else{
	      	++t;
	        ss>>b;
	        if(a+b==10){
	        	if(f==9)flag=1;
	        	if(f!=9)++bonus[t+1];
	        }
	        sc+=b*bonus[t];
	        ++t;
	      }
	      if(f==9&&flag){
	        ss>>a;
	        sc+=a*bonus[t];
	        ++t;
	        break;
	      }
	      ++f;
	    }
	    score.push_back(make_pair(num,sc));
    }
    sort(score.begin(),score.end(),compare);
    for(int i=0;i<m;++i){
    	cout<<score[i].first<<" "<<score[i].second<<endl;
    }
  }
  return 0;
}

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].id < a[j-1].id){
	t = a[j];
	a[j] = a[j-1];
	a[j-1] = 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<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> p[40];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			int n;
			scanf("%d",&n);
			int s=0;
			int two=0;
			int one=0;
			for(int j=0;j<9;j++){
				int v;
				scanf("%d",&v);
				s+=v*(two+one);
				one=two;
				two=0;
				s+=v;
				if(v==10){
					two++;
					continue;
				}
				int L=v;
				scanf("%d",&v);
				s+=v*(two+one);
				one=two;
				two=0;
				s+=v;
				if(L+v==10){
					one++;
				}
			}
			bool ok=false;
			int v;
			scanf("%d",&v);
			s+=v*(two+one);
			one=two;
			two=0;
			s+=v;
			if(v==10){
		//		two++;
				ok=true;
			}
			int L=v;
			scanf("%d",&v);
			s+=v*(two+one);
			one=two;
			two=0;
			s+=v;
			if(v==10){
		//		two++;
				ok=true;
			}else if(v>0&&L+v==10){
		//		one++;
				ok=true;
			}
			if(ok){
				scanf("%d",&v);
				s+=v*(two+one);
				one=two;
				two=0;
				s+=v;
			}
			p[i]=make_pair(-s,n);
		}
		std::sort(p,p+a);
		for(int i=0;i<a;i++)printf("%d %d\n",p[i].second,-p[i].first);
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>

#define FRAMES 10
#define SCORES 21

using namespace std;
class Student{
public:
	Student(){
		id = 0;
		for(int i = 0; i < SCORES; ++i){
			scores[i] = 0;
		}
	}
	int id;
	int scores[SCORES];
	void calculateScore(){
		int nScore = 0;
		int frame = 0;
		for(int i = 0; i < SCORES; ++frame){
			if( frame != FRAMES-1 ){
				int a = scores[ i ];
				int b = scores[ i + 1 ];
				if( a == 10 ){
					nScore += a + b + scores[ i + 2 ];
					++i;
				}else if( a + b == 10 ){
					nScore += a + b + scores[ i + 2 ];
					i+=2;
				}else{
					nScore += a + b;
					i+=2;
				}
			}else{
				nScore += scores[ i ] + scores[ i + 1 ] + scores[ i + 2 ];
				break;
			}
		}
		score = nScore;
	}
	int score;
};
bool operator < ( const Student &t1, const Student &t2 ){
	if( t1.score == t2.score ){
		return t1.id < t2.id;
	}else
		return t1.score > t2.score;
}
istream & operator >> (istream &is, Student &std){
	int i = 0;
	is >> std.id;
	while( true ){
		is >> std.scores[i++];
		if( is.get() == '\n' )
			break;
	}
	return is;
}
ostream & operator << (ostream &os, Student &std){
	os << std.id << ' ' << std.score;
	return os;
}

int main()
{

	while( true ){
		int n;
		vector< Student > vStudents;
		cin >> n;
		if( n == 0 ) break;
		for(int i = 0; i < n; ++i){
			Student t;
			cin >> t;
			t.calculateScore();
			vStudents.push_back( t );
		}
		sort( vStudents.begin() , vStudents.end() );
		for(int i = 0; i < n; ++i){
			cout << vStudents[i] << '\n';
		}
	}
	return 0;
}