Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"sort"
	"fmt"
)

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;
	      if(prev == STRIKE) 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 <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

struct Student{
	int id,score;
};

struct Data{
	int score,first,second;
	bool strike,spare;
};

int main(){

	int num,tmp,index,pre_score;
	char buf[120];
	Student students[40];
	Data game_data[12];
	bool First;

	while(true){
		scanf("%d",&num);
		if(num == 0)break;

		for(int i = 0; i < 40; i++){
			students[i].score = 0;
		}

		getchar();

		for(int i = 0; i < num; i++){
			for(int k=0; k <= 11; k++){
				game_data[k].score = 0;
				game_data[k].first = 0;
				game_data[k].second = 0;
				game_data[k].strike = false;
				game_data[k].spare = false;
			}

			First = true;

			fgets(buf,120,stdin);

			tmp = 0;
			index = 0;
			pre_score = -1;
			for(int k = 0; buf[k] != '\n'; k++){
				if(buf[k] >= '0' && buf[k] <= '9'){
					tmp = 10*tmp + (buf[k] - '0');

					if(buf[k+1] == '\n'){
						if(pre_score == -1){
							game_data[index].first = tmp;
							game_data[index].score = tmp;
						}else{
							game_data[index].second = tmp;
							game_data[index].score = pre_score + tmp;
						}
					}
				}else{
					if(First){
						students[i].id = tmp;
						First = false;
					}else{

						if(pre_score == -1){
							game_data[index].first = tmp;
							if(tmp == 10){
								game_data[index].score = 10;
								game_data[index].strike = true;
								index++;
							}else{
								pre_score = tmp;
							}

						}else{
							game_data[index].second = tmp;
							game_data[index].score = pre_score + tmp;
							if(pre_score + tmp == 10){
								game_data[index].spare = true;
							}

							index++;

							pre_score = -1;
						}
					}

					tmp = 0;
				}
			}

			for(int k = 0; k <= 11; k++){
				students[i].score += game_data[k].score;
					if(k <= 8 && game_data[k].spare == true){
					students[i].score += game_data[k+1].first;
				}

				if(k <= 8 && game_data[k].strike == true){
					students[i].score += game_data[k+1].first;
					if(game_data[k+1].first == 10){
						students[i].score += game_data[k+2].first;
					}else{
						students[i].score += game_data[k+1].second;
					}
				}
			}
		}

		for(int i = 1; i <= num-1; i++){
			for(int k = num-1; k >= i; k--){
				if(students[k].score > students[k-1].score)swap(students[k],students[k-1]);
				else if(students[k].score == students[k-1].score && students[k].id < students[k-1].id)swap(students[k],students[k-1]);
			}
		}

		for(int i=0; i < num; i++){
			printf("%d %d\n",students[i].id,students[i].score);
		}
	}

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

pair<int, int> p[10000];
struct Sorter
{
	bool operator()(const pair<int, int>& a, const pair<int, int>& b)
	{
		return a.first > b.first || a.first == b.first && a.second < b.second;
	}
};
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
		{
			int no;
			scanf("%d", &no);

			int total = 0;
			int W = 0;
			int a, b;
			for (int f = 1; f <= 10; ++f)
			{
				scanf("%d", &a);
				total += a;
				if (W)
				{
					total += a * (W % 10);
					W /= 10;
				}
				if (a == 10 && f != 10)
				{
					W += 11;
					continue;
				}

				scanf("%d", &b);
				total += b;
				if (W)
				{
					total += b;
					W /= 10;
				}
				if (a + b == 10)
					++W;
			}
			if (a == 10 || a + b == 10)
			{
				int c;
				scanf("%d", &c);
				total += c;
			}
			p[i] = make_pair(total, no);
		}
		sort(p, p+n, Sorter());
		for (int i = 0; i < n; ++i)
			printf("%d %d\n", p[i].second, p[i].first);
	}

	return 0;
}