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 <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	while(true){
		int n; cin >> n;
		if(n == 0)break;
		set<pair<int,int>> st;
		string z; getline(cin, z);
		for(int i = 0; i < n; i++){
			string raw;
			getline(cin, raw);
			stringstream ss; ss << raw;
			int id; ss >> id;
			pair<int, int> score;
			vector<pair<int, int>> t(10);
			for(int j = 0; j < 10; j++){
				ss >> t[j].first;
				if(t[j].first == 10 && j != 9)continue;
				if(ss.eof())break;
				ss >> t[j].second;
			}
			for(auto e : t)score.first += e.first + e.second;
//			for(auto e : t)cerr << e.first << "," << e.second << " ";
			int ls = 0;
			if(!ss.eof())ss >> ls;
			score.first += ls;
//			cerr << ls << endl;
//			cerr << score.first << endl;
			for(int j = 0; j < 10; j++){
				if(t[j].first == 10){
					if(j == 9){
						//score.first += t[j].second + ls;
					}
					else{
						score.first += t[j+1].first;
						if(t[j+1].first == 10 && j+1 < 9){
							score.first += t[j+2].first;
						}
						else{
							score.first += t[j+1].second;
						}
					}
				}
				else if(t[j].first + t[j].second == 10){
					if(j == 9){
						//score.first += ls;
					}
					else{
						score.first += t[j+1].first;
					}
				}
//				cerr << score.first << " ";
			}
//			cerr << endl;
			score.first *= -1;
			score.second = id;
			st.insert(score);
		}
//		cerr << st.size() << endl;
		for(auto e : st){
			cout << e.second << " "<< (-e.first) << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;

int main(){
	int n;
	while(cin>>n&&n){
		vector<pair<int,int> >dat;
		for(int i=0;i<n;i++){
			int mem;
			cin>>mem;
			vector<int> scr;
			int a,b,c;
			for(int j=0;j<10;j++){
				cin>>a;
				scr.PB(a);
				if(a!=10||j==9){
					cin>>b;
					scr.PB(b);
				}else continue;
				if(j==9&&(a+b==10||a+b==20)){
					cin>>c;
					scr.PB(c);
				}else continue;
			}
			int ans=0,k=0;
			for(int j=0;j<10;j++){
				if(j==9){
					for(int x=k;x<scr.size();x++)ans+=scr[x];
					continue;
				}
				if(scr[k]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k++;
					continue;
				}
				if(scr[k]+scr[k+1]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k+=2;
					continue;
				}
				ans+=scr[k]+scr[k+1];
				k+=2;
			}
			dat.PB(MP(ans,mem));
		}
		sort(dat.begin(),dat.end());
		for(int i=dat.size()-1;i>=0;i--){
			cout<<dat[i].second<<" "<<dat[i].first<<endl;
		}
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > score(n);
        for(int i=0; i<n; ++i){
            cin >> score[i].second;
            score[i].second = -score[i].second;

            vector<vector<int> > pin(10, vector<int>(2, 0));
            for(int j=0; j<10; ++j){
                cin >> pin[j][0];
                if(j == 9 || pin[j][0] != 10)
                    cin >> pin[j][1];
                score[i].first += pin[j][0] + pin[j][1];

                if(j > 0 && pin[j-1][0] == 10){
                    score[i].first += pin[j][0] + pin[j][1];
                    if(j > 1 && pin[j-2][0] == 10)
                        score[i].first += pin[j][0];
                }
                else if(j > 0 && pin[j-1][0] + pin[j-1][1] == 10)
                    score[i].first += pin[j][0];
            }
            if(pin[9][0] + pin[9][1] == 10 || pin[9][0] + pin[9][1] == 20){
                int a;
                cin >> a;
                score[i].first += a;
            }
        }

        sort(score.rbegin(), score.rend());
        for(int i=0; i<n; ++i)
            cout << -score[i].second << ' ' << score[i].first << endl;
    }
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int s[30][5];

P operator+(P a, int d) {
	rep(i, d) {
		if (!~s[a.first][a.second + 1]) {
			a.first++; a.second = 0;
		}
		else a.second++;
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d%*c", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			string S; getline(cin, S);
			stringstream buf(S);
			int id; buf >> id;
			int f = 1; bool b = 0;
			while (f <= 9) {
				if (!buf >> s[f][b])abort();
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			buf >> s[10][0] >> s[10][1];
			if (s[10][0] == 10 || s[10][1] == 10 || s[10][0] + s[10][1] == 10)buf >> s[10][2];
			P p(1, 0);
			while (p.first <= 9) {
				if (s[p.first][p.second] == 10) {
					P a = p + 1, b = p + 2;
					s[p.first][p.second] += s[a.first][a.second] + s[b.first][b.second];
				}
				if (p.second&& s[p.first][p.second - 1] + s[p.first][p.second] == 10) {
					P a = p + 1;
					s[p.first][p.second] += s[a.first][a.second];
				}
				p = p + 1;
			}
			int cnt = 0;
			for (int i = 1; i <= 10; i++)rep(j, 3) {
				if (~s[i][j])cnt += s[i][j];
			}
			v.push_back(P(cnt, id));
		}
		sort(v.begin(), v.end(), [](P a, P b) {
			if (a.first != b.first)return a.first > b.first;
			return a.second < b.second;
		});
		for (auto p : v) {
			printf("%d %d\n", p.second, p.first);
		}
	}
}