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 <algorithm>
#include <functional>
#include <vector>
#include <sstream>
#include <cassert>
using namespace std;

struct Score {
    int student_number;
    int score;
    Score() {
        score = 0;
    }
    bool operator>(const Score& o) const {
        return score == o.score ? student_number < o.student_number : score > o.score;
    }
};

int calc_score(istringstream& is) {
    vector< pair<int, int> > frame(12); // フレームごとの投球情報. 1-indexed

    int score = 0;

    int bonus_spare = 0;
    int bonus_strike = 0;
    int pin;
    int cur_frame = 1;
    int cur_pin = 0;
    bool first_bowl = true;
    while (is >> pin) {
        if (cur_frame != 11) score += pin;
        if (bonus_spare) {
            score += pin * bonus_spare;
            bonus_spare = bonus_strike;
            bonus_strike = 0;
        } 
//        cout << score << ' ';

        if (cur_frame == 11) {
            if (first_bowl) {
                frame[cur_frame].first = pin;
                first_bowl = false;
            } else {
                frame[cur_frame].second = pin;
            }
            continue;
        }

        if (pin == 10) {
//            assert(first_bowl == true);
            frame[cur_frame].first = 10;
            frame[cur_frame].second = -1; // 投球がなかったことのフラグ
            cur_frame++;
            bonus_spare++;
            bonus_strike++;
            first_bowl = true;
            continue;
        } 

        if (first_bowl) {
            frame[cur_frame].first = pin;
            first_bowl = false;
        } else {
            frame[cur_frame].second = pin;
            if (frame[cur_frame].first + frame[cur_frame].second == 10) 
                bonus_spare++;
            first_bowl = true;
            cur_frame++;
        }
    }
    return score;
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        cin.ignore(1);
        vector<Score> info(n);
        for (int i = 0; i < n; i++) {
            Score score;
            string s; getline(cin, s);
            istringstream is(s);
            is >> score.student_number;
            score.score = calc_score(is);
            info[i] = score;
        }
        sort(info.begin(), info.end(), greater<Score>());
        for (int i = 0; i < info.size(); i++) {
            cout << info[i].student_number << ' ' << info[i].score << endl;
        }
    }
    return 0;
}

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;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int i,j,k;
long long int a,s[50000],d[50000][300],f,g[50000],h,z[50000][300],x[50000][300],c,q[50000];
long long int aa[50000][300],ss;
int main(void)
{
	while(1){
		f=0;
		h=0;
		c=0;
		ss=0;
		h=0;
		scanf("%lld",&a);
		if(a<3) break;
		for(i=0;i<a;i++){
			q[i]=0;
			for(j=0;j<12;j++) x[i][j]=0;
		}
		for(i=0;i<a;i++){
			f=18;
			g[i]=0;
			scanf("%lld",&s[i]);
			while(1){
				scanf("%lld",&d[i][g[i]]);
				if(d[i][g[i]]==10) f--;
				g[i]++;
				f--;
				if(f==0) break;
			}
			scanf("%lld",&d[i][g[i]]);
			scanf("%lld",&d[i][g[i]+1]);
			if(d[i][g[i]]==10||d[i][g[i]+1]==10||d[i][g[i]]+d[i][g[i]+1]==10){
				scanf("%lld",&d[i][g[i]+2]);
				g[i]++;
			}
			g[i]+=2;
		}
		for(i=0;i<a;i++){
			j=0;
			c=0;
			while(1){
				if(d[i][j]==10){
					z[i][c]=2;
					x[i][c]=10;
					ss++;
					j++;
					aa[i][c]=j;
					c++;
				}
				else if(d[i][j]+d[i][j+1]==10){
					z[i][c]=1;
					x[i][c]=10;
					j=j+2;
					aa[i][c]=j;
					c++;
				}
				else if(d[i][j]+d[i][j+1]!=10){
					z[i][c]=0;
					x[i][c]=d[i][j]+d[i][j+1];
					j=j+2;
					aa[i][c]=j;
					c++;
				}
				else if(j=g[i]-1&&d[i][j]!=10){
					x[i][c]=d[i][j];
					z[i][c]=0;
					j++;
					aa[i][c]=j;
					c++;
				}
				if(j>=g[i])	break;
			}
		}
		for(i=0;i<a;i++){
			for(j=0;j<9;j++){
				q[i]+=x[i][j];
				if(z[i][j]==2){
					if(z[i][j+1]==2){
						if(z[i][j+2]==2)
							q[i]=q[i]+x[i][j+1]+x[i][j+2];
						else if(z[i][j+2]!=2)
							q[i]=q[i]+x[i][j+1]+d[i][aa[i][j+1]];
					}
					else if(z[i][j+1]!=2){
						q[i]+=x[i][j+1];
					}
				}
				else if(z[i][j]==1){
					q[i]+=d[i][aa[i][j]];
				//	printf("1  %d\n",d[i][aa[i][j]]);
				}
			}
			q[i]=q[i]+x[i][9]+x[i][10]+x[i][11];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(q[i]<q[j]){
					ss=q[i];
					q[i]=q[j];
					q[j]=ss;
					ss=s[i];
					s[i]=s[j];
					s[j]=ss;
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%lld %lld\n",s[i],q[i]);
		}
	}
	return 0;
}