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

using namespace std;

int main(void)
{
	int n;
	while (cin >> n, n){
		cin.ignore();
		pair <int, int> data[40];
		string str;
		for (int i = 0; i < n; i++){
			getline(cin, str);

			stringstream ss(str);
			vector <int> pin;
			for (int x; ss >> x;){
				pin.push_back(x);
			}

			int score = 0;
			for (int frame = 1, j = 1; frame <= 10; frame++){
				if (frame == 10){
					while (j < pin.size()){
						score += pin[j];
						j++;
					}
					break;
				}
				if (pin[j] == 10){
					// st
					score += pin[j] + pin[j + 1] + pin[j + 2];
					j++;
				}
				else {
					score += pin[j] + pin[j + 1];
					if (pin[j] + pin[j + 1] == 10){
						// sp
						score += pin[j + 2];
					}
					j += 2;
				}
			}
			data[i].first = -score;
			data[i].second = pin[0];
		}
		sort(data, data + n);
		for (int j = 0; j < n; j++){
			cout << data[j].second << " " << -data[j].first << endl;
		}
	}

	return 0;
}

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

main(){
	int n,num ;
	while( cin >> n , n ){
		int ans[100][2] = {} ;
		for( int i=0 ; i<n ; i++ ){
			cin >> num ;
			
			int c[11][2] = {} , sum[10] = {} ;
			for( int j=0 ; j<10 ; j++ ){
				
				cin >> c[j][0] ;
				if( j==9 || c[j][0]!=10 ) cin >> c[j][1] ;
				if( j==9 && c[j][0]+c[j][1]>=10 ) cin >> c[j+1][0] ;
				
				sum[j] += c[j][0] + c[j][1] ;
			}
			sum[9] += c[10][0] ;
			
			for( int j=0 ; j<9 ; j++ ){
				if( c[j][0] == 10 ){
					sum[j] += c[j+1][0] + c[j+1][1] ;
					if( i!=8 && c[j+1][0] == 10 && c[j+1][1] == 0 ) sum[j] += c[j+2][0] ;
				}
				else if( c[j][0]+c[j][1] == 10 ){
					sum[j] += c[j+1][0] ;
				}
			}
			for( int j=1 ; j<10 ; j++ ) sum[j] += sum[j-1] ;
			
			ans[i][0] = num ; ans[i][1] = sum[9] ;
		}
		
		for( int i=0 ; i<n ; i++ ){
			for( int j=i+1 ; j<n ; j++ ){
				if( ans[i][1] < ans[j][1] ||
					ans[i][1] == ans[j][1] && ans[i][0] > ans[j][0] ){
						swap( ans[i] , ans[j] ) ;
				}
			}
		}
		
		for( int i=0 ; i<n ; i++ ){
			cout << ans[i][0] << ' ' << ans[i][1] << endl ;
		}
	}
}

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<100;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);}
                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<sstream>
#include<map>
using namespace std;

int main()
{
  int n,player,score[21];
  int i;
  int frame,sum;
  multimap< int,int,greater<int> > result;
  multimap<int,int>::iterator it;
  string s;
  while(getline(cin,s)){
    stringstream ss(s);
    ss>>n;
    if(!n)break;

    result.clear();
    while(n-->0){
      getline(cin,s);
      stringstream ss(s);
      ss>>player;
      for(i=0;i<21;i++)ss>>score[i];
      i=sum=0;
      frame=1;
      while(frame<=9){
	if(score[i]+score[i+1]<10){
	  sum+=score[i]+score[i+1];
	  i+=2;
	}else if(score[i]==10){
	  sum+=score[i]+score[i+1]+score[i+2];
	  i++;
	}else if(score[i]+score[i+1]==10){
	  sum+=score[i]+score[i+1]+score[i+2];
	  i+=2;
	}
	frame++;
      }
      if(score[i]+score[i+1]<10)sum+=score[i]+score[i+1];
      else if(score[i]==10)sum+=score[i]+score[i+1]+score[i+2];
      else if(score[i]+score[i+1]==10)sum+=score[i]+score[i+1]+score[i+2];
      result.insert(make_pair(sum,player));
    }

    for(it=result.begin();it!=result.end();it++)
      cout<<it->second<<" "<<it->first<<endl;
  }
}