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 <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;
            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 <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <sstream>
#include <cstdio>
using namespace std;
typedef pair <int,int> p;
vector<p> V;

p score(string str) {
  stringstream ss;
  string s;
  int number;
  ss << str;
  ss >> number;
  int frame = 1,play=1,point[11] = {};
  int spare[22] = {},strike[22] = {};
  bool check = true;
  while(ss >> s) {
    int pin = atoi(s.c_str());
    if(check) point[frame] += pin;
    for(int i=1;i<11;i++) {
      if(strike[i]>0) {
	point[i]+=pin;
	strike[i]--;
      }
      if(spare[i]>0) {
	point[i]+=pin;
	spare[i]--;
      }
    }
    if(play==1&&pin==10) {
      strike[frame]=2;
      if(frame!=10) frame++;
      else check = false;
      play=1;
      continue;
    }
    if(play==1&&pin!=10) {
      play++;
      continue;
    }
    if(play==2&&point[frame]==10) {
      spare[frame] = 1;
      if(frame!=10)frame++;
      else check = false;
      play=1;
      continue;      
    }
    if(play==2&&point[frame]!=10) {
      frame++;
      play=1;
      continue;
    }
  }
  int sum=0;
  for(int i=1;i<=10;i++) {
    //  cout << point[i] << " ";
    sum += point[i];
  }
  // cout << sum << endl;
  p ans;
  ans.first = sum;
  ans.second = number;
    return ans;
}
  
int main() {
  int m;
  string str;
  while(scanf("%d\n",&m),m) {
    for(int i=0;i<m;i++) {
      p temp;
      getline(cin,str);
      temp = score(str);
      V.push_back(temp);
    }
    sort(V.rbegin(),V.rend());
    for(unsigned int i=0;i<V.size();i++) {
      cout << V[i].second << " " << V[i].first << endl;
    }
    V.clear();
  }
}

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), S(10), C(10);
    VI T(10, 0);
    int t = 0;
    for ( int i = 0; i < 10; ++ i ) {
        F[i] = 0, S[i] = 0, C[i] = 0;
        if ( A[t] == 10 ) {
            F[i] = A[t++];
        } else {
            F[i] = A[t++];
            S[i] = A[t++];
        }
        if ( i == 9 ) {
            if ( F[i] == 10 ) {
                S[i] = A[t++];
            }
            C[i] = 0;
            if ( F[i] + S[i] >= 10 ) C[i] = A[t++];
        } else {
        }
    }

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

    int addScore = 0;
    for ( int i = 0; i < 10; ++ i ) {
        if ( i < 9 ) {
            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;
}