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++: //Name: Bowling
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * 倒したピン数を監視しながらフレーム数を管理する。
 * スペアかストライクが出た場合、次以降の投球を見て追加点を決める。
 *
 * オーダーは O(NM + M log M)。
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>

using namespace std;

bool solve(bool first) {
    int M;
    if(!(cin >> M)) return false;
    if(!M) return false;

    cin.ignore();
    vector<pair<int,int>> v;
    while(M--) {
        string line;
        getline(cin, line);
        istringstream is(line);

        int id;
        is >> id;

        vector<int> history;
        int pin;
        while(is >> pin) history.push_back(pin);

        int frame = 1;
        int score = 0;
        int acc = 0, turn = 0;
        for(int i = 0; i < history.size(); ++i) {
            ++turn;
            score += history[i];
            acc += history[i];
            if(frame != 10) {
                if(acc == 10) {
                    if(turn == 1) score += history[i+1] + history[i+2];
                    else if(turn == 2) score += history[i+1];
                    turn = 2;
                }
                if(turn == 2) {
                    ++frame;
                    acc = 0;
                    turn = 0;
                }
            }
        }
        v.emplace_back(-score, id);
    }
    sort(begin(v), end(v));
    for(const auto &p : v) {
        cout << p.second << ' ' << -p.first << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

C++: 

#include <iostream>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int, int> P;
int main(){
	int n,a,psum,c,take,f;
	string str,out;
	P tmp,array[40];
	vector<P> plist;
	vector<int> point;
	while(cin >> n,n){
		plist.clear();
		getline(cin,str);
		for(int i = 0;i < n;++i){
			psum = c = take = 0;
			getline(cin,str);
			stringstream buf(str);
			point.clear();
			f = 1;
			while(buf >> out){
				a = atoi(out.c_str());
				if(f) {
					tmp.second = a;
					f = 0;
				}
				else{
					point.push_back(a);
				}
			}
			point.push_back(0);
			point.push_back(0);
			int k = 0;
			for(int j = 0;j < 10;++j){
				if(point[k] == 10){
					psum += point[k] + point[k + 1] + point[k + 2];
					++k;
				}
				else if(point[k] + point[k + 1] == 10){
					psum += point[k] + point[k + 1] + point[k + 2];
					k += 2;
				}
				else {
					psum += point[k] + point[k + 1];
					k += 2;	
				}
			}
			tmp.first = psum;
			plist.push_back(tmp);
			buf.clear();
		}
		sort(plist.begin(),plist.end());
		reverse(plist.begin(),plist.end());
		for(int i = 0;i < plist.size();++i){
			cout << plist[i].second << " " << plist[i].first << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<map>
int F(int*a)
{
	int s,f,c,r;
	for(s=f=c=r=0;c<9;)
	{
		r+=*a;
		if(*a+s==10)
		{
			if(f)r+=a[1];
			else r+=a[1]+a[2];
			f=0,s=0;
			++c;
		}
		else
		{
			if(f)f=0,++c,s=0;
			else f=1,s=*a;
		}
		++a;
	}
	s=*a+a[1];
	if(s>9)s+=a[2];
	return r+s;
}
int main()
{
	int m,i,j,x[32],l;
	char*p,s[256];
	std::pair<int,int>a[40];
	while(scanf("%d",&m),m)
	{
		for(i=0;i<m;++i)
		{
			scanf("%d",&a[i].second);
			fgets(s,256,stdin);
			for(l=0,p=strtok(s," ");p;p=strtok(0," "))
				x[l++]=atoi(p);
			a[i].first=-F(x);
		}
		std::sort(a,a+m);
		for(i=0;i<m;++i)printf("%d %d\n",a[i].second,-a[i].first);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  
  typedef pair<int, int> Pii;

  int N;
  
  while(cin >> N && N) {
    
    vector<Pii> SCORE(N);
    
    for(int m=0; m<N; m++){
      
      cin >> SCORE[m].second;
      
      int all = 0;
      int strike[11] = {};
      
      for(int i=1; i<=10; i++){
        int sc; cin >> sc;
 
        if( strike[i-1] == 2 ) all += sc;
        if( i-2 >= 0 && strike[i-1] == 2 && strike[i-2] == 2 ) all += sc;
        if( strike[i-1] == 1 ) all += sc;
 
        if(sc == 10){
          all += sc;
          strike[i] = 2;
        }
        else {
          int add; cin >> add;
          if( strike[i-1] == 2 ) all += add;
          all += sc + add;
          if( sc + add == 10 ) strike[i] = 1;
        }
      }
       
      if( strike[10] == 2 ){
        int sc, add; cin >> sc >> add;
        all += sc + add;
        if( strike[9] == 2 ) all += sc;
      }
      else if( strike[10] == 1 ){
        int sc; cin>>sc;
        all += sc;
      }
      
      SCORE[m].first = -all;
      
    }
 
    sort(SCORE.begin(), SCORE.end());
    
    for(int i=0; i<N; i++){
      cout << SCORE[i].second << ' ' << -SCORE[i].first << endl;
    }
    
  }
  
  return 0;
}