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

int main(){
	int m;
	while(cin >> m && m){
		vector< pair<int,int> > OK;
		for(int x = 0 ; x < m ; x++){
			int prev = 0 , ans = 0;
			vector< vector<int> > v;
			int num; cin >> num;
			for(int i = 0 ; i < 10 ; i++){
				int a;
				vector<int> t;
				cin >> a;
				t.push_back(a);
				if(i != 9){
					if(a!=10){
						int b;
						cin >> b;
						t.push_back(b);
					}
				}else{
					if(a==10){
						int b,c;
						cin >> b >> c;
						t.push_back(b);
						t.push_back(c);
					}else{
						int b; cin >> b;
						t.push_back(b);
						if(a+b==10){
							int c;
							cin >> c;
							t.push_back(c);
						}
					}
				}
				v.push_back(t);
			}
			for(int i = 0 ; i < 9 ; i++){
				if(v[i][0]==10){
					ans += v[i][0];
					if(v[i+1].size() < 2){
						ans += v[i+1][0] + v[i+2][0];
					}else{
						ans += v[i+1][0] + v[i+1][1];
					}
				}else if(v[i][0]+v[i][1] == 10){
					ans += 10;
					ans += v[i+1][0];
				}else{
					ans += v[i][0]+v[i][1];
				}
			}
			for(int j = 0 ; j < v[9].size() ; j++)
				ans += v[9][j];
			OK.push_back(make_pair(-ans,num));
		}
		sort(OK.begin(),OK.end());
		for(int i = 0 ; i < OK.size() ; i++)
			cout << OK[i].second << " " << -OK[i].first << endl;
	}
}

C++: #include<iostream>
#include<map>
#include<functional>
#include<cstring>
using namespace std;

int main(void){
	int n;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		multimap<int,int, greater<int> > s;
		for(int i=0;i<n;i++){
			int num,sc[10][3],sck[10],res=0;
			memset(sc,0,sizeof(sc));
			memset(sck,0,sizeof(sck));
			scanf("%d",&num);
			for(int j=0;j<10;j++){
				if(j<9)for(int k=0;k<2;k++){
					scanf("%d",&sc[j][k]);
					if(sc[j][k]==10)break;
				}
				if(j==9)for(int k=0;k<3;k++){
					scanf("%d",&sc[j][k]);
					if(k==1 && sc[j][0]+sc[j][1]<10)break;
				}
			}
			sck[9]=sc[9][0]+sc[9][1]+sc[9][2];
			for(int j=0;j<9;j++){
				if(sc[j][0]==10){
					sck[j]=10;
					if(sc[j+1][0]==10)sck[j]+=10+sc[j+2][0];
					else sck[j]+=sc[j+1][0]+sc[j+1][1];
				}else if(sc[j][0]+sc[j][1]==10){
					sck[j]=10+sc[j+1][0];
				}else sck[j]=sc[j][0]+sc[j][1];
			}
			for(int j=0;j<=9;j++)res+=sck[j];
			s.insert(make_pair(res,num));
		}
		multimap<int,int, greater<int> >::iterator it=s.begin();
		while(it!=s.end()){
			cout << (*it).second << " " << (*it).first << endl;
			it++;
		}
	}
    return 0;
}

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

typedef pair<int,int> P;

int main(){
	int n;
	while(cin >> n,n){
		int id;
		vector<P> vec;
		for(int ii = 0;ii < n;ii++){
			int add[21] = {},score[21] = {},sum = 0,frame = 0,tou = 1;
			cin >> id;
			for(int i = 0;frame < 10;i++){
				cin >> score[i];
				//cout << score[i] << " " << frame << " " << tou << endl;
				add[i]++;
				if(score[i] == 10){
					if(frame != 9){
						frame++;
						add[i + 1]++;
						add[i + 2]++;
					}else{
						if(tou == 3) frame++;
						tou++;
					}
				}else if(tou == 2 && score[i] + score[i - 1] == 10){
					if(frame == 9) tou = 3;
					else{
						frame++;
						add[i + 1]++;
						tou = 1;
					}
				}else if(tou == 2){
					frame++;
					tou = 1;
				}else if(tou == 3) frame++;
				else tou++;
			}
			for(int i = 0;i < 21;i++){
				sum += score[i] * add[i];
			}
			vec.push_back(P(sum,-id));
		}
		sort(vec.begin(),vec.end(),greater<P>());
		for(int i = 0;i < n;i++){
			cout << -vec[i].second << " " << vec[i].first << endl;
		}
	}
	return 0;
}