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<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int meibo[10010],st[10100][20],sp[10100][20],score[10100];

int main(){
  while(true){//game
    int a;
    cin>>a;
    if(a==0){break;}
    a++;
    for(int i=0;i<10001;i++){
      meibo[i]=score[i]=0;
      for(int j=0;j<11;j++){
	st[i][j]=sp[i][j]=0;
      }
    }
    for(int i=1;i<a;i++){
      cin>>meibo[i];
      for(int j=1;j<11;j++){
	int be=0,af=0;
	cin>>be;
	if(j>2&&st[meibo[i]][j-2]>0){
	  score[meibo[i]]+=be;
	  st[meibo[i]][j-2]--;
	}
	if(j>1&&st[meibo[i]][j-1]>0){
	  score[meibo[i]]+=be;
	  st[meibo[i]][j-1]--;
	}
	if(j>1&&sp[meibo[i]][j-1]>0){
	  score[meibo[i]]+=be;
	  sp[meibo[i]][j-1]--;
	}
	if(be==10){st[meibo[i]][j]=2;}
	else{
	  cin>>af;
	  if((be+af)==10){sp[meibo[i]][j]=1;}
	  if(j>1&&st[meibo[i]][j-1]>0){
	    score[meibo[i]]+=af;
	    st[meibo[i]][j-1]--;
	  }
	  if(j==10&&be+af>=10){
	    int cn;cin>>cn;
	    score[meibo[i]]+=cn;
	  }
	}
	if(j==10&&be==10){
	  cin>>af;
	  if((be+af)==10){sp[meibo[i]][j]=1;}
	  if(j>1&&st[meibo[i]][j-1]>0){
	    score[meibo[i]]+=af;
	    st[meibo[i]][j-1]--;
	  }
	  int cn;cin>>cn;
	  score[meibo[i]]+=cn;
	}
	score[meibo[i]]=score[meibo[i]]+be+af;
      }
    }
    int l=1;
    while(l < a){
      for(int i=1;i<a;i++){
	int ext=0;
	for(int j=1;j<a;j++){
	  if(score[meibo[i]]<score[meibo[j]]){
	    ext++;
	  }
	}
	if(ext==0){
	  cout<<meibo[i]<<" "<<score[meibo[i]]<<endl;
	  score[meibo[i]]=0;
	  break;
	}
      }
      l++;
    }
  }///game
}

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

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


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, g = 1;
      for(int i = 0 ; g <= 10 ; ){
	if(g == 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];
	  g++;
	}
	else if(rec[i] + rec[i+1] == 10){
	  res += 10 + rec[i+2];
	  i+=2;
	  g++;
	}
	else if(rec[i] == 10){
	  res += 10 + rec[i+1] + rec[i+2];
	  i++;
	  g++;
	}
	else{
	  res += rec[i] + rec[i+1];
	  i+=2;
	  g++;
	}
      }
      data.push_back(P(-res, ID));
    }
    sort(data.begin(), data.end());
    for(int i = 0 ; i < n ; i++){
      cout << data[i].second << ' ' << -data[i].first << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

// vector の表示用デバッグ
template<class T>
void debug(vector<T> v){
	cout << "[debug]" << endl << "{";
	for(int i = 0 ; i < v.size() ; i++ ){
		cout << v[i];
		if( i < v.size()-1 )
			cout  << ", ";
	}
	cout << "}" << endl << endl;
}

//string型からint型に変換する
int s_to_i(string s){
    int n = 0;
    for(unsigned int i=0 ; i < s.size() ; ++i ){
        n *= 10;
        n += s[i] - '0';
    }
    return n;
}

// 文字列を半角スペース区切りで数値に分割する
vector<int> split_words(string s){
    bool flag = false;
    vector<string> vs;
    string str;
    s.push_back(' ');
    for(int i=0 ; i < s.size() ; i++ ){
        char c = s[i];
        if( flag == false ){
            if( c != ' ' ){
                flag = true;
                str.clear();
                str.push_back( c );
            }
        }else{
            if( c != ' ' ){
                str.push_back( c );
            }
            if( c == ' ' ){
                flag = false;
                vs.push_back( str );
                str.clear();
            }
        }
    }
    vector<int> v;
    for(int i=0 ; i < vs.size() ; i++ ){
    	v.push_back( s_to_i( vs[i] ) );
    }
    return v;
}

// v[0] := 学籍番号, v[1..v.size()-1] := 点数の記録
// score := 点数, pos := 位置
// frame := フレーム数, k := 0のとき1投目, 1のとき2投目
// (-スコア,学籍番号)を返す
P solve(vector<int>& v, int score, int pos, int frame, int k){
	P result;
	
	if( frame > 10 || pos >= v.size() ){
		result.second = v[0];
		result.first = -score;
		return result;
	}else{
		if( k == 0 ){ // 1投目
			if( v[pos] == 10 ){ // ストライクのとき	
				score += v[pos] + v[pos+1] + v[pos+2];
				return solve( v , score , pos+1 , frame+1 , 0 );
			}else{
				score += v[pos];
				return solve( v , score , pos+1 , frame , 1 );
			}
		}else{ // 2投目
			if( v[pos-1] + v[pos] == 10 ){ // スペアのとき
				score += v[pos] + v[pos+1];
				return solve( v , score , pos+1 , frame+1 , 0 );
			}else{
				score += v[pos];
				return solve( v , score , pos+1 , frame+1 , 0 );
			}
		}
	}
	
	return result;
}

int main(){
	int n;
	while( cin >> n , n ){
		cin.ignore();
		vector<P> ans;
		for(int i=0 ; i < n ; i++ ){
			string s;
			getline(cin,s);
			vector<int> v = split_words(s);
			P p = solve( v , 0 , 1 , 1 , 0 );
			ans.push_back(p);
		}
		
		sort( ans.begin() , ans.end() );
		for(int i=0 ; i < ans.size() ; i++ ){
			cout << ans[i].second << " " << -ans[i].first << endl;;
		}
	}
}