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<bits/stdc++.h>
using namespace std;

class T{

public:
  int indx;
  int point;

  bool operator < (const T &a)const{
    if(point == a.point){
      return indx < a.indx;
    }else{
      return point > a.point;
    }
  }
};

int main(){


  vector<T> result;
  int game[21];
  int m;


  while(cin >> m && m){
    result = vector<T>(m);
    for(int i=0; i<m; i++){
      result[i].point=0;
    }

    for(int i=0; i<m; i++){

      cin>>result[i].indx;

      int indx=0;
      while(indx < 20){

	cin >> game[indx];

	//10game
	if(indx==18){
	  cin >> game[++indx];

	  if(game[indx-1]+game[indx] >= 10){
	    cin >> game[++indx];
	  }
	  else{
	    game[++indx]=0;
	  }
	  break;
	}
	//1 to 9 game
	else{
	  if(game[indx]==10){
	    game[++indx]=-1;
	    indx++;
	  }
	  else{
	    cin >> game[++indx];
	    indx++;
	  }
	}
      }
      //while

      /*  cout << endl;
      for(int m=0; m<21; m++){
	cout << game[m] << ' ';
      }cout << endl;
      */

      //score
      indx = 0;
      while(indx<21){

	if(indx == 18){
	  result[i].point+= game[18]+game[19]+game[20];
	  break;
	}
	else{

	  result[i].point+=game[indx];

	  if(game[indx]==10){
	    int work=0;
	    int k=2;
	    while(work<2){
	      if(game[indx+k]!=-1){
		result[i].point+=game[indx+k];
		work++;
	      }
	      k++;
	    }
	    indx+=2;
	  }
	  else{
	    result[i].point+=game[++indx];
	    if(game[indx-1]+game[indx]==10)
	      result[i].point+=game[indx+1];

	    indx++;
	  }
	}

	//cout << "test " <<result[i][1] << endl;;

      }	
      
    }

    //sort
    sort(result.begin(), result.end());
 
    for(int i=0; i<m; i++){
      cout << result[i].indx << ' ' << result[i].point << endl;
    }

  }


  return 0;
}

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

int main(){
  int m;
  while(cin >> m, m){
    vector<string> I(m);
    vector<int> S(m,0);
    for(int i = 0; i < m; ++i){
      cin >> I[i];
      vector<int> t;
      for(int j = 0; j < 20; ++j){
        int s;
        cin >> s;
        if(j < 18 and s == 10) ++j;
        t.push_back(s);
      }
      if(t[t.size()-1]+t[t.size()-2] >= 10){
        int s;
        cin >> s;
        t.push_back(s);
      }
      int l = 0;
      for(size_t j = 0; j < t.size(); ++j){
        int tmp = t[j], k = 0;
        ++l;
        if(tmp < 10 and j+1 < t.size()) tmp += t[++j], ++k;
        if(l < 10 and tmp == 10){
          if(j+1 < t.size()) S[i] += t[j+1];
          if(k == 0 and j+2 < t.size()) S[i] += t[j+2];
        }
        S[i] += tmp;
      }
      
    }
    vector<pair<int,string>> V;
    for(int i = 0; i < m; ++i)
      V.emplace_back(S[i],I[i]);
    sort(V.rbegin(), V.rend());
    for(auto p : V)
      cout << p.second << " " << p.first<< endl;
  }
}

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

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<pair<int, int> > v;
		
		for (int i = 0; i < n; i++){
			int stNo;
			scanf("%d", &stNo);
			
			int frame = 0;
			int frameScore[10] = {0}, remain[10] = {0};
			int prev = -1;
			int ct = 0;
			while (frame < 10){
				int pin;
				scanf("%d", &pin);
				frameScore[frame] += pin;
				
				if (frame == 9){
					if (ct == 1 && frameScore[frame] < 10) frame++;
					else if (ct == 2) frame++;
					ct++;
				}
				
				for (int j = 0; j < 10; j++){
					if (remain[j]){
						frameScore[j] += pin;
						remain[j]--;
					}
				}
				
				if (frame < 9){
					if (pin == 10 && prev != -1) return (1);
					if (pin == 10){
						remain[frame] = 2;
						frame++;
						prev = -1;
					}
					else if (prev + pin == 10){
						remain[frame] = 1;
						frame++;
						prev = -1;
					}
					else if (~prev){
						frame++;
						prev = -1;
					}
					else if (prev == -1) prev = pin;
				}
			}
			
			int sum = 0;
			for (int j = 0; j < 10; j++) sum += frameScore[j];
			v.push_back(make_pair(-sum, stNo));
		}
		
		sort(v.begin(), v.end());
		for (int i = 0; i < n; i++){
			printf("%d %d\n", v[i].second, -v[i].first);
		}
	}
	
	return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main(){
 for(int d;cin>>d,d;){
  vector<pair<int,int> > result;
  for(int i=0;i<d;i++){
   int name,score=0,a,b,k=0;
   cin>>name;
   for(int i=0;i<10;i++){
    cin>>a;score+=a;
    if(k&4)score+=a,k&=3;
    if(k&2)score+=a;
    if(k&1)score+=a,k&=6;
    if(a==10){
     if(k&2)k|=4;k|=2;}
    else{cin>>b;score+=b;
      if(k&2)score+=b,k&=5;
      if(a+b==10)k|=1;}
    }
    if(k&2){cin>>a>>b;score+=k&4?2*a+b:a+b;}
    if(k&1){cin>>a;score+=a;}
    result.push_back(make_pair(-score,name));
    }
    sort(result.begin(),result.end());
    for(int i=0;i<d;i++)cout<<result[i].second<<" "<<-result[i].first<<endl;
  }
}