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 <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct P {
  int id, score;
  vector<int> pin;
  P() {}
  P(int id, vector<int> pin) : id(id), pin(pin) {
    int game = 0, turn = 0, pz = pin.size(), pos = -1;
    for (int i = 0; i < pz; i++) {
      if (pos < 0 && game == 9) pos = i;
      if (pin[i] == 10 || turn == 1) {
        game++; turn = 0;
      } else {
        turn = 1;
      }
    }
    turn = 0;
    int res = 0;
    for (int i = 0; i < pos; i++) {
      if (turn == 0 && pin[i] == 10) {
        res += pin[i] + pin[i + 1] + pin[i + 2];
        turn = 0;
      } else if (turn == 1 && pin[i - 1] + pin[i] == 10) {
        res += pin[i] + pin[i + 1];
        turn = 0;
      } else {
        res += pin[i];
        turn ^= 1;
      }
    }
    for (int i = pos; i < pz; i++) {
      res += pin[i];
    }
    score = res;
  }
  bool operator < (P other) {
    return score != other.score ? score > other.score : id < other.id;
  }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int m;
  while (cin >> m, m) {
    cin.ignore();
    vector<P> ps;
    for (int i = 0; i < m; i++) {
      string s;
      getline(cin, s);
      stringstream ss;
      ss << s;
      ss >> s;
      int id = stoi(s);
      vector<int> a;
      while (ss >> s) {
        a.emplace_back(stoi(s));
      }
      ps.emplace_back(P(id, a));
    }
    sort(ps.begin(), ps.end());
    for (int i = 0; i < m; i++) {
      cout << ps[i].id << " " << ps[i].score << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define P pair<int,int>

bool cmp(P p,P q){
  if( p.first > q.first ) return true;
  if( p.first < q.first ) return false;
  if( p.second < q.second ) return true;
  return false;
}

int main(){
  int m;

  while( cin>>m && m ){
    vector<int> v;
    vector<P> s;
    P p; // 得点、学籍番号
    //    cout << "m="<< m << endl; // **********************

    for( int lp=0;lp<m;lp++ ){
      cin >> p.second; // 学籍番号
      //      cout << " std"<<lp<<"="<<p.second << endl; //********
      v.clear();
      int n=9, a,b;
      while( n>0 ){ // 9投目まで
	cin >> a; v.push_back( a );
	if( a!=10 ){ cin >> a; v.push_back( a ); }
	n--;
      }
      //      cout << endl;

      // 10投目
      cin >> a >> b;
      v.push_back( a );      v.push_back( b );
      if( a+b>=10 ){  cin >> a; v.push_back( a ); }
      p.first = 0; // 得点
      n=0;
      for( int i=0,j;i<9;i++ ){
	j = v[n] + v[n+1];
	p.first += j;
	if( v[n]==10 ){ // strike
	  p.first += v[n+2];
	}else {
	  if( j==10 ) p.first += v[n+2];
	  n++;
	}
	n++;
      }
      while( n<(int)v.size() ) p.first += v[n++];

      //      cout << "  score="<<p.first << endl;
      s.push_back( p );
    }
    
    sort( s.begin(),s.end(), cmp );
      for( unsigned int i=0;i<s.size();i++ )
	cout << s[i].second << " " << s[i].first << endl;

  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> pii;

int culc(string str) {
	istringstream ss(str);
	int n = count(str.c_str(), str.c_str() + str.size(), ' ');
	vector<int> in(n);
	REP(i, n) ss >> in[i];
	
	int pos = 0, ans = 0;
	REP(frame, 10) {
		if (frame == 9)  {
			FOR(i, pos, n) ans += in[i]; 
		}
		else {
			if (in[pos] == 10)
				ans += in[pos] + in[pos + 1] + in[pos + 2];
			else {
				ans += in[pos] + in[pos + 1];
				if (in[pos] + in[pos + 1] == 10) ans += in[pos + 2];
				pos++;
			}
		}
		pos++;
	}
	
	return ans;
}

int main() {
	int n;
	while (cin >> n, n) {
		vector<pii> ans;
		REP(i, n) {
			int num;
			string str;
			cin >> num;
			getline(cin, str);
			
			ans.push_back(pii(-culc(str), num));
		}
		sort(ans.begin(), ans.end());
		REP(i, ans.size()) {
			printf("%d %d\n", ans[i].second, -ans[i].first);
		}
	}
	
	return 0;
}