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++: #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", &m), m) {
		vector<P>v;
		rep(i, m) {
			string s; cin >> s;
			stringstream ss(s);
			int d, cnt = 0;
			while (ss >> d) {
				cnt++;
			}
			if (cnt == 22)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));*/
		}
		puts("Hello,world!");
		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);
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

struct P {
	int id;
	int score;
	bool operator < (const P &t) const {
		if (score != t.score) return score > t.score;
		return id < t.id;
	}
	P(int id, int score): id(id), score(score){}
};

int n;

int main()
{
	while (scanf("%d", &n), n){
		vector<P> ps;
		for (int c = 0; c < n; c++){
			int id;
			scanf("%d", &id);
			
			int score = 0;
			int t = 0;
			int sp = 0;
			int st = 0;
			while (t < 10){
				if (t == 9){
					int a[3] = {};
					int m = 2;
					for (int i = 0; i < m; i++){
						scanf("%d", &a[i]);
						score += a[i] * (1 + sp + st);
						sp = st;
						st = 0;
						if (i == 1 && a[0] + a[1] >= 10) m++;
					}
					t++;
					continue;
				}
				
				int a;
				scanf("%d", &a);
				
				score += a * (1 + sp + st);
				sp = st;
				st = 0;
				
				if (a == 10){
					st++;
					t++;
					continue;
				}
				
				int b;
				scanf("%d", &b);
				
				score += b * (1 + sp + st);
				sp = st;
				st = 0;
				
				
				if (a + b == 10) sp++;
				t++;
			}
			
			ps.push_back(P(id, score));
		}
		
		sort(ps.begin(), ps.end());
		for (int i = 0; i < n; i++){
			printf("%d %d\n", ps[i].id, ps[i].score);
		}
	}
	return 0;
}

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

#define f first
#define s second
typedef pair<int, int> P;

int ID, rec[22];

void split(string s){
  stringstream ss(s);
  int i = 0;
  while(ss >> rec[i]) i++;
}

bool compare(const P x, const P y){
  if(x.f == y.f){
    return x.s < y.s;
  }
  return x.f > y.f;
} 

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

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int i,j,k;
	int a,s[100],d[100][30],f,g[100],h,z[100][30],x[100][30],c,q[100];
	int aa[100][30],ss;
	while(1){
		f=0;
		h=0;
		c=0;
		ss=0;
		h=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			for(j=0;j<21;j++){
				aa[i][j]=0;
				z[i][j]=0;
			}
		}
		for(i=0;i<a;i++){
			g[i]=0;
			q[i]=0;
			for(j=0;j<21;j++) x[i][j]=0;
		}
		for(i=0;i<a;i++){
			f=18;
			g[i]=0;
			scanf("%d",&s[i]);
			while(1){
				scanf("%d",&d[i][g[i]]);
				if(d[i][g[i]]==10) f--;
				g[i]++;
				f--;
				if(f==0) break;
			}
			scanf("%d",&d[i][g[i]]);
			scanf("%d",&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("%d",&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]];
				}
			}
			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("%d %d\n",s[i],q[i]);
		}
	}
	return 0;
}