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;
typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    vector<P> a;
    a.resize(n+1);
    string s;
    getline(cin,s);
    for(int j=0; j<n; j++) {
      getline(cin,s);
      stringstream ss;
      ss << s;
      ss >> a[j].second;
      a[j].first=0;
      vector<int> b;
      int x;
      while(ss >> x) b.push_back(x);
      int i=0,k=0;
      vector<int> c;
      c.resize(b.size()+1);
      fill(c.begin(),c.end(),0);
      while(i<b.size()) {
        k++;
        a[j].first+=b[i];
        if(i&&c[i-1]) a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i]==10) {
          if(k<10)c[i]=2;
          i++;
          continue;
        }
        i++;
        a[j].first+=b[i];
        if(i>=2&&c[i-2]==2) a[j].first+=b[i];
        if(b[i-1]+b[i]==10) {
          if(k<10)c[i]=1;
          i++;
          continue;
        }
        i++;
        if(k==10) {
          a[j].first+=b[i];
          i++;
        }
      }
    }
    sort(a.rbegin(),a.rend());
    for(int i=0; i<n; i++) cout << a[i].second << " " << a[i].first << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct P{
  int n, p;
  P(int n, int p):n(n),p(p){};
  bool operator<(const P& r)const{
    return p == r.p ? n > r.n : p < r.p;
  }
};

int m;

int solve(int *f, int n){
  int res = 0;
  //  printf("%d ", *f);
  if(*f == 1 || *f == 2){ res = n*2; (*f)--;}
  else if(*f == 3){ res = n*3; *f = 1;}
  else res = n;
  //  printf("%d\n", *f);
  return res;
}

int main(){
  while(scanf("%d", & m) && m){
    int a, b, sf, sum, n;
    priority_queue<P>q;
    rep(i, m){
      sf = sum = 0;
      scanf("%d", &n);
      rep(j, 9){
	//	printf("j: %d\n", j);
	//	printf("%d\n", sf);
	//	printf("%d\n", sum);
	scanf("%d", &a);
	sum += solve(&sf, a);
	if(a == 10){ sf += 2; continue;}


	scanf("%d", &b);
	sum += solve(&sf, b);
	if(a + b == 10){ sf += 1; continue;}

      }
      scanf("%d", &a);
      //      printf("sf:%d\n", sf);
      if(a == 10){
	sum += solve(&sf, a);
	sf += 2;
	//	printf("%d %d\n", sum, sf);
	scanf("%d", &a);
	sum += solve(&sf, a) - a;
	//	printf("%d %d\n", sum, sf);
	scanf("%d", &a);
	sum += a;
      }else{
	sum += solve(&sf, a);
	scanf("%d", &b);
	sum += solve(&sf, b);
	if(a + b == 10){
	  scanf("%d", &b);
	  sum += b;
	}
      }
      q.push(P(n, sum));
    }
    while(!q.empty()){
      P p = q.top(); q.pop();
      printf("%d %d\n", p.n, p.p);
    }
  }
  return 0;
}

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

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){
						remain[frame] = 2;
						frame++;
						prev = -1;
					}
					else if (prev + pin == 10){
						remain[frame] = 1;
						frame++;
						prev = -1;
					}
					else if (~prev){
						frame++;
						prev = -1;
					}
					else 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("%04d %d\n", v[i].second, -v[i].first);
		}
	}
	
	return (0);
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

int s[10][5];

P operator+(P a, int d) {
	rep(i, d) {
		if (!~s[a.first][a.second + 1]) {
			a.first++; a.second = 0;
		}
		else a.second++;
	}
	return a;
}
int main() {
	int m;
	while (scanf("%d%*c", &m), m) {
		vector<P>v;
		rep(i, m) {
			string s; getline(cin, s);
			stringstream ss(s);
			int d, cnt = 0;
			while (ss >> d) {
				cnt++;
			}
			if (cnt == 13)abort();
			/*
			memset(s, -1, sizeof(s));
			int id; scanf("%d", &id);
			int f = 0; bool b = 0;
			while (f < 9) {
				scanf("%d", &s[f][b]);
				if (s[f][b] > 10)abort();
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			scanf("%d%d", &s[9][0], &s[9][1]);
			if (s[9][0] + s[9][1] >= 10)scanf("%d", &s[9][2]);
			P p(0, 0);
			while (p.first < 9) {
				if (s[p.first][p.second] == 10) {
					P a = p + 1, b = p + 2;
					s[p.first][p.second] += s[a.first][a.second] + s[b.first][b.second];
				}
				if (p.second&& s[p.first][p.second - 1] + s[p.first][p.second] == 10) {
					P a = p + 1;
					s[p.first][p.second] += s[a.first][a.second];
				}
				p = p + 1;
			}
			int cnt = 0;
			rep(i, 10)rep(j, 3) {
				if (~s[i][j])cnt += s[i][j];
			}
			v.push_back(P(cnt, id));*/
		}/*
		sort(v.begin(), v.end(), [](P a, P b) {
			if (a.first != b.first)return a.first > b.first;
			return a.second < b.second;
		});
		for (auto p : v) {
			printf("%d %d\n", p.second, p.first);
		}*/
	}
	puts("Hello,world!");
}