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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    int m;
    cin >> m;

    if(m == 0) break;

    vector<pii> ans;

    REP(i,m){
      int id;
      cin >> id;

      int point[23] = {};
      REP(i,23){
        point[i] = -1;
      }

      int game = 0;
      while(game != 9){
        int tmp;
        int pin = 10;

        cin >> tmp;
        pin -= tmp;

        //strikeの時
        if(pin == 0){
          point[game*2] = 10;
          game++;
          continue;
        }

        point[game*2] = tmp;

        cin >> tmp;
        pin -= tmp;

        point[game*2+1] = tmp;

        game++;
      }

      //game = 10
      int tmp;
      int cnt = 0;

      cin >> tmp;
      point[game*2] = tmp;
      cnt += tmp;

      cin >> tmp;
      cnt += tmp;
      point[game*2+1] = tmp;

      if(cnt >= 10){
        cin >> tmp;
        point[game*2+2] = tmp;
      }

      //点数計算
      int sum = 0;
      REP(i,9){
        //stike
        if(point[i*2] == 10){
          if(point[(i+1)*2] == 10){
            if(i == 8){
              sum += 10 + 10 + point[(i+1)*2+1];
            }else{
              sum += 10 + 10 + point[(i+2)*2];
            }
          }else{
            sum += 10 + point[(i+1)*2] + point[(i+1)*2+1];
          }
          //spare
        }else if(point[i*2] + point[i*2+1] == 10){
          sum += point[i*2] + point[i*2+1] + point[(i+1)*2];
        }else{
          sum += point[i*2] + point[i*2+1];
        }

      //cout << sum << endl;
      }

      sum += point[9*2] + point[9*2+1] + max(0, point[9*2+2]);
      //cout << sum << endl;
      ans.pb(MP(-sum, id));
    }
    SORTV(ans);
    REPI(itr, ans){
      cout << itr->second << " " << itr->first * -1 << endl;
    }
  }
  return 0;
}

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

int main() {
  int n;
  while(cin >> n && n) {
    vector<P> a;
    a.resize(n);
    string s;
    getline(cin,s);
    for(int j=0; j<n; j++) {
      getline(cin,s);
      stringstream ss;
      ss << s;
      ss >> a[j].second;
      a[j].second*=-1;
      a[j].first=0;
      vector<int> b;
      int x;
      while(ss >> x) b.push_back(x);
      int i=0,k=0;
      vector<int> c;
      c.resize(b.size()+1);
      fill(c.begin(),c.end(),0);
      while(i<b.size()) {
        k++;
        a[j].first+=b[i];
        if(i&&c[i-1]) a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i]==10) {
          if(k<10)c[i]=2;
          i++;
          continue;
        }
        i++;
        if(i>=b.size()) break;
        a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i-1]+b[i]==10) {
          if(k<10)c[i]=1;
          i++;
          continue;
        }
        i++;
      }
    }
    sort(a.rbegin(),a.rend());
    for(int i=0; i<n; i++) cout << -a[i].second << " " << a[i].first << endl;
  }
  return 0;
}

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

pair<int,int> getScore() {
  int id;
  cin >> id;
  int a = 0, b = 0, ext = 0, s = 0, t = 0, sum = 0;
  for(int f = 1; f <= 10; ++f) {
    cin >> s;
    sum += s * (1 + a + b);
    b = a; a = 0;
    if(s == 10) {
      if(f == 10) ext = 2;
      else ++a;
      continue;
    }

    cin >> t;
    sum += t * (1 + a + b);
    b = a; a = 0;
    if(s+t == 10) {
      if(f == 10) ext = 1;
      else ++b;
      continue;
    }
  }
  while(ext--) {
    cin >> s;
    sum += s * (1 + a + b);
    b = a; a = 0;
    //if(s == 10) ++a;
  }

  return make_pair(-sum, id);
}

int main() {
  int n;
  while(cin >> n && n) {
    vector<pair<int,int> > v;
    for(int i = 0; i < n; ++i) {
      v.push_back(getScore());
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size(); ++i) {
      cout << v[i].second << " " << -v[i].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 ){
		vector<P> ans ;
		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.push_back( P(sum[9],num) ) ;
		}
		
		sort( ans.begin() , ans.end() , greater<P>() ) ;
		for( int i=0 ; i<n ; i++ ){
			cout << ans[i].second << ' ' << ans[i].first << endl ;
		}
	}
}