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 <iterator>
#include <vector>
#include <set>

using namespace std;

template<class T1, class T2>
T1 lexical_cast(T2 a){
  T1 tmp;
  stringstream ss;
  ss << a; ss >> tmp;
  return tmp;
}

int main(){
  string buff;
  int n;

  while(getline(cin, buff), n = lexical_cast<int>(buff)){
    set<pair<int, int>, greater<pair<int, int> > > ans;

    for(int i = 0; i < n; i++){
      stringstream ss;
      int id;
      int point = 0;
      int frame = 0;

      getline(cin, buff); ss << buff; ss >> id;
      
      vector<int> v((istream_iterator<int>(ss)),
		    istream_iterator<int>());

      enum state{
	NONE = 0,
	SPARE = 1,
	STRIKE = 2
      };

      state prev  = NONE;
      state pprev = NONE;
      
      int vv = 0;
      for(int f = 0; f < 10; f++){
	int now = v[vv++];

	point += now;
	if(prev  != NONE)   point += now;
	if(pprev == STRIKE) point += now;

	if(now == 10){
	  if(f == 9){
	    int now2 = v[vv++];
	    point += now2;
	    if(prev == STRIKE) point += now2;
	    if(now2 == 10)
	      point += v[vv++];
	  }

	  pprev = prev;
	  prev  = STRIKE;
	}else{
	  int now2 = v[vv++];
	  point += now2;

	  if(prev  == STRIKE) point += now2;

	  pprev = NONE;
	  prev  = NONE;

	  if(now + now2 == 10){
	    if(f == 9){
	      int now3 = v[vv++];
	      point += now3;
	    }
	    prev = SPARE;
	  }
	}
	// cout << "f=" << f+1 << ": " << point << " ";
	// cout << "prev=" << prev << " " << "pprev=" << pprev << endl;
      }

      ans.insert(make_pair(point, id));
    }

    for(set<pair<int, int> >::iterator it = ans.begin();
	it != ans.end();
	++it){
      cout << it->second << " " << it->first << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>

using namespace std;

void solve(vector<vector<int> > v){
    map<int,int> point2num;
    vector<int> points;
    for(int i=0;i<v.size();i++){
        int num = v[i][0];
        vector<int> frame(11);
        frame[0] = 0;
        int f=1;int j=1;
        while(true){
            if(f==11)break;
            int x = v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1]+v[i][j+2];
                f++;j++;
                continue;
            }
            j++;
            x = x+v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1];
                f++;j++;
                continue;
            }
            frame[f] = x;
            f++;j++;
            continue;
        }
        int p=0;
        for(int j=0;j<frame.size();j++){
            p+=frame[j];
        }
        points.push_back(p);
        point2num.insert(map<int,int>::value_type(p,num));
    }
    sort(points.begin(),points.end(),greater<int>());
    for(int i=0;i<points.size();i++){
        cout << point2num[points[i]] << " " << points[i] << endl;
    }
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        cin.ignore();
        vector<vector<int> > v(n);
        for(int i=0;i<n;i++){
            string s;
            getline(cin,s);
            istringstream is(s);
            int x;
            while(is >> x){
                v[i].push_back(x);
            }
        }
        solve(v);
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

#define f first
#define s second
typedef pair<int, int> P;

int ID, rec[22];

int split(string s){
  stringstream ss(s);
  int i = 0;
  while(ss >> rec[i]) i++;
  return i;
}

bool compare(const P x, const P y){
  if(x.f == y.f){
    return x.s < y.s;
  }
  return x.f > y.f;
} 

int main(){
  int n;
  while(cin >> n, n){
    vector<P> data;
    string s;

    for(int cs = 0 ; cs < n ; cs++){
      memset(rec, 0, sizeof(rec));
      cin >> ID;
      getline(cin, s);
      int N = split(s);

      int res = 0, flame = 1;
      for(int i = 0 ; flame <= 10 ; ){
	if(flame == 10){
	  if(rec[i] + rec[i+1] == 10) res += 10 + rec[i+2];
	  else if(rec[i] == 10) res += 10 + rec[i+1]+rec[i+2];
	  else res += rec[i] + rec[i+1];
	  flame++;
	}
	else if(rec[i] + rec[i+1] == 10){
	  res += 10 + rec[i+2];
	  i+=2;
	  flame++;
	}
	else if(rec[i] == 10){
	  res += 10 + rec[i+1] + rec[i+2];
	  i++;
	  flame++;
	}
	else{
	  res += rec[i] + rec[i+1];
	  i+=2;
	  flame++;
	}
      }
      data.push_back(P(res, ID));
    }
    sort(data.begin(), data.end(), compare);
    for(int i = 0 ; i < n ; i++){
      cout << data[i].second << ' ' << data[i].first << endl;
    }
  }
  return 0;
}