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
}

Python: def get_point(info):
  info.reverse()
  sum_acc = 0
  NORMAL, SPARE, STRIKE, DOUBLE = 0, 1, 2, 3
  flag = NORMAL
  game_num = 0
  while info:
    if game_num != 9:
      down_num1 = info.pop()
      if down_num1 != 10:
        down_num2 = info.pop()
        if flag == SPARE:
          sum_acc += down_num1 * 2 + down_num2
        elif flag == STRIKE:
          sum_acc += down_num1 * 2 + down_num2 * 2
        elif flag == DOUBLE:
          sum_acc += down_num1 * 3 + down_num2 * 2
        else:
          sum_acc += down_num1 + down_num2
        
        if down_num1 + down_num2 == 10:
          flag = SPARE
        else:
          flag = NORMAL
      
      else:
        if flag in (SPARE, STRIKE):
          sum_acc += down_num1 * 2
        elif flag == DOUBLE:
          sum_acc += down_num1 * 3
        else:
          sum_acc += down_num1
        if flag in (STRIKE, DOUBLE):
          flag = DOUBLE
        else:
          flag = STRIKE
      game_num += 1

    else:
      down_num1, down_num2 = info.pop(), info.pop()
      if flag == SPARE:
        sum_acc += down_num1 * 2 + down_num2
      elif flag == STRIKE:
        sum_acc += down_num1 * 2 + down_num2 * 2
      elif flag == DOUBLE:
        sum_acc += down_num1 * 3 + down_num2 * 2
      else:
        sum_acc += down_num1 + down_num2
      if info:
        sum_acc += info.pop()
  
  return sum_acc

while True:
  m = int(input())
  if m == 0:
    break
  score = [list(map(int, input().split())) for _ in range(m)]
  score_mp = [(info[0], get_point(info[1:])) for info in score]
  score_mp.sort(key=lambda x:-x[1])
  for pair in score_mp:
    print(*pair)

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 == 12)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<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
typedef pair<int,int> P;
int s2i(string str){
  int x=0;
  istringstream iss(str);
  iss >> x;
  return x;
}
int main(){
  int n;
  cin >> n;

  while(n!=0){
    int i,j,k;
    vector<P> v;
    P p;
   
    string str,buf;
    getline(cin,str);
    for(i=0;i<n;i++){
      getline(cin,str);
      //cout << str << endl;
      stringstream ss(str);
      ss >> buf;
      p.second=s2i(buf)*(-1);
      vector <int> b;
      while(ss>>buf){
        b.push_back(s2i(buf));
      }
      bool s=false;
      int c=0; 
      p.first=0;
      for(j=0;j<b.size();j++){
        if(c==9){
          p.first+=b[j];
        }else{
          if(s){
            p.first+=b[j];
            if(b[j-1]+b[j]==10){
              if(j<b.size()-1)
                p.first+=b[j+1];
            }
            c++;
            s=false;
          }else{
            p.first+=b[j];
            if(b[j]==10) {
              if(j<b.size()-1)
                p.first+=b[j+1];
              if(j<b.size()-2)
                p.first+=b[j+2];
              c++;
            }else{
              s=true;
            }
          }
        }
      }
      v.push_back(p);
    }
    sort(v.begin(),v.end(),greater<P>());
    for(i=0;i<v.size();i++){
      cout << -1*v[i].second << " " << v[i].first << endl;
    }

    cin >> n;
    }
  return 0;
}