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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define al(s) s.begin(),s.end()

typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef pair<int, ppi> pipp;


int main()
{
	int m;
	while (cin >> m&&m)
	{
		vector<pi> a;
		for (int r = 0; r < m; r++)
		{
			int num; cin >> num;
			int score = 0;
			int k[21], j[21];
			memset(k, -1, sizeof(k));
			memset(j, -1, sizeof(j));
			for (int i = 0; i < 18; i += 2)
			{
				cin >> k[i];
				if (k[i] == 10)
				{
					j[i] = 2;
				}
				else
				{
					cin >> k[i + 1];
					if (k[i] + k[i + 1] == 10)
					{
						j[i + 1] = 1;
					}
				}
			}
			cin >> k[18] >> k[19];
			if (k[18] + k[19] >= 10)
			{
				cin >> k[20];
			}
			for (int i = 0; i < 21; i++)
			{
				if (j[i] == 1)
				{
					k[i] += k[i + 1];
				}
				else if (j[i] == 2)
				{
					k[i] += k[i + 2];
					if (k[i + 3] == -1)
					{
						k[i] += k[i + 4];
					}
					else
					{
						k[i] += k[i + 3];
					}
				}
			}

			for (int i = 0; i < 21; i++)
			{
				score += max(0, k[i]);
			}
			a.push_back(pi(score, num));
		}
		sort(a.begin(), a.end());
		reverse(a.begin(), a.end());
		bool che = true;
		while (che)
		{
			che = false;
			for (int i = 1; i < m; i++)
			{
				if (a[i].second < a[i - 1].second&&a[i].first == a[i - 1].first)
				{
					swap(a[i], a[i - 1]);
					che = true;
				}
			}

		}
		for (int i = 0; i < m; i++)
		{
			cout << a[i].second << " " << a[i].first << endl;
		}

	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<pair<int, int> > score;
    cin >>ws;
    for(int k=0; k<n; k++){
      vector<int> bowl;
      string s;
      int x = 0,sn,p=0;
      bool f = true;
      getline(cin,s);
      for(int i=0; i<s.size(); i++){
	if(s[i] == ' '){
	  if(f){sn = x;f = false;}
	  else{bowl.push_back(x);}
	  x = 0;
	}
	else{x = x*10+s[i]-'0';}
      }
      bowl.push_back(x);
      int a=0,b=0,c=0,d=0,e=2;
      for(int i=0; i<bowl.size(); i++){
	p+=bowl[i]*(a+1);
	d+=bowl[i];
	e--;
	a = b;
	b = 0;
	if(e == 1 && d == 10){
	  c++;
	  e = 2;
	  d = 0;
	  if(c<10){
	    a++;
	    b++;
	  }
	}
	if(e == 0){
	  c++;
	  e = 2;
	  if(d == 10 && c<10){a++;}
	  d = 0;
	}
      }
      score.push_back(make_pair(p,sn));
    }
    sort(score.begin(),score.end());
    for(int i=score.size()-1; i>0; i--){
      cout<< score[i].second<<" "<<score[i].first<<endl;
    }
  }
  return 0;
}