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 <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


II solve( int no, VI A ) {
    VI F(10, 0), S(10, 0), C(10, 0);
    VI T(10, 0);
    int t = 0;
    for ( int i = 0; i < 10; ++ i ) {
        F[i] = 0, S[i] = 0, C[i] = 0;
        if ( i == 9 ) {
            F[i] = A[t++];
            S[i] = A[t++];
            C[i] = 0;
            if ( F[i] + S[i] >= 10 ) C[i] = A[t++];
        } else {
            if ( A[t] == 10 ) {
                F[i] = A[t++];
            } else {
                F[i] = A[t++];
                S[i] = A[t++];
            }
        }
    }

    for ( int i = 0; i < 10; ++ i ) {
        T[i] = F[i] + S[i] + C[i];
    }

    int addScore = 0;
    for ( int i = 0; i < 9; ++ i ) {
        if ( F[i] == 10 ) {
            if ( i < 8 ) {
                if ( F[i+1] == 10 ) {
                    addScore += 10 + F[i+2];
                } else {
                    addScore += F[i+1] + S[i+1];
                }
            } else if ( i == 8 ) {
                addScore += F[9] + S[9];
            }
        } else if ( F[i] + S[i] >= 10 ) {
            addScore += F[i+1];
        }
    }
    return II( accumulate( T.begin(), T.end(), 0 ) + addScore, no );
}

int main() {
    string line;
    while ( getline( cin, line ) ) {
        if ( line == "0" ) break;
        ISS iss( line );
        int n;
        iss >> n;
        VII scores( n );
        for ( int i = 0; i < n; ++ i ) {
            getline( cin, line );
            ISS iss( line );
            int no;
            iss >> no;
            int a;
            VI A;
            while ( iss >> a ) A.push_back( a );
            scores[i] = solve( no, A );
        }
        sort( scores.rbegin(), scores.rend() );
        for ( int i = 0; i < n; ++ i ) {
            cout << scores[i].second << " " << scores[i].first << endl; 
        }
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<int, string> Ps;

Ps data[40];
int cnt[11];
int main(){
  int m, a, b, c, score;
  while(cin >> m && m){
    rep(i, m){
      score = 0;

      fill(cnt, cnt + 10, 0);
      cin >> data[i].second;
      rep(j, 10){
	cin >> a;
	score += a;
	rep(k, 10) if(cnt[k] > 0){
	  cnt[k]--;
	  score += a;
	}

	if(a == 10){

	  if(j != 9)cnt[j]+=2;
	  else{
	    cin >> b >> c;
	    score += b + c;
	    rep(k, 10)if(cnt[k]){
	      cnt[k]--;
	      score += b;
	    }
	  }
	  
	}else{

	  cin >> b;
	  score += b;
	  rep(k, 10) if(cnt[k] > 0){
	    cnt[k]--;
	    score += b;
	  }
	  if(a + b == 10){
	    if(j != 9)cnt[j]++;
	    else{
	      cin >> c;
	      score += c;
	    }
	  }
	}
      }
      data[i].first = -score;
    }
    sort(data, data + m);
    rep(i, m){
      cout << data[i].second << " " << -data[i].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;
		while(n--){
			int mem;
			cin>>mem;
			vector<int> scr;
			int a,b,c;
			for(int i=0;i<10;i++){
				cin>>a;
				scr.PB(a);
				if(a!=10||i==9){
					cin>>b;
					scr.PB(b);
				}else continue;
				if(i==9&&(a+b>=10)){
					cin>>c;
					scr.PB(c);
				}else continue;
			}
			int ans=0,k=0;
			for(int i=0;i<9;i++){
				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;
			}
			while(k<scr.size())ans+=scr[k++];
			dat.PB(MP((-1)*ans,mem));
		}
		sort(dat.begin(),dat.end());
		for(int i=0;i<dat.size();i++){
			cout<<dat[i].second<<" "<<dat[i].first*(-1)<<endl;
		}
	}
}