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<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
using namespace std;

bool comp(pair<int,int> x, pair<int,int> y){
    if(x.second != y.second)    return x.second > y.second;
    else                        return x.first < y.first;
}

int main(){
    int m;
    while(1){
        scanf("%d\n", &m);
        if(m == 0)  break;

        vector<pair<int,int>> v;
        
        for(int i = 0; i < m; i++){
            string x;
            getline(cin, x);
            stringstream ss;
            ss << x;
            int id, score = 0;
            ss >> id;
            int tmp, pos = 0, accum = 0, flame = 1;
            int bias[30] = {};
            bool first = true;
            while(flame < 10){
                ss >> tmp;
                score += tmp * (1 + bias[pos]);
                accum += tmp;
                if(first){
                    if(accum == 10){
                        bias[pos+1]++;
                        bias[pos+2]++;
                        accum = 0;
                        flame++;
                    }else{
                        first = false;
                    }
                }else{
                    if(accum == 10){
                        bias[pos+1]++;
                    }
                    first = true;
                    accum = 0;
                    flame++;
                }
                pos++;
            }

            while(ss >> tmp){
                score += tmp * (1 + bias[pos]);
                pos++;
            }    

            v.push_back({id, score});
        }

        sort(v.begin(), v.end(), comp);

        for(int i = 0; i < v.size(); i++){
            cout << v[i].first << " " << v[i].second << endl;
        }
    }
    return 0;
}

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

int N;
void solve(){
    vector<pair<int,int> >R;

    while(N--){
        int p;scanf("%d",&p);
        vector<int>V;

        for(int i=0;i<10;i++){
            int a,b;
            scanf("%d",&a);
            V.push_back(a);
            if(a!=10||i==9){
                scanf("%d",&b);
                V.push_back(b);
            }
            if(a+b>=10&&i==9){
                int c;
                scanf("%d",&c);
                V.push_back(c);
            }
        }
        int ans=0,cur=0;
        for(int i=0;i<9;i++){
            ans+=V[cur];
            if(V[cur]==10){
                ans+=V[cur+1]+V[cur+2];
            }
            else{
                cur++;
                ans+=V[cur];
                if(V[cur-1]+V[cur]==10)ans+=V[cur+1];
            }
            cur++;
        }
        while(cur<V.size())ans+=V[cur++];
        R.push_back(pair<int,int>(ans,9999-p));
    }
    sort(R.rbegin(),R.rend());

    for(int i=0;i<R.size();i++)printf("%d %d\n",-(R[i].second-9999),R[i].first);
}

int main(){
    while(scanf("%d",&N),N)solve();
    return 0;
}

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

int N;
void solve(){
    vector<pair<int,int> >R;

    while(N--){
        int p;scanf("%d",&p);
        vector<int>V;

        for(int i=0;i<10;i++){
            int a,b;
            scanf("%d",&a);
            V.push_back(a);
            if(a!=10||i==9){
                scanf("%d",&b);
                V.push_back(b);
            }
            if(a+b>=10&&i==9){
                int c;
                scanf("%d",&c);
                V.push_back(c);
            }
        }
        int ans=0,cur=0;
        for(int i=0;i<9;i++){
            ans+=V[cur];
            if(V[cur]==10){
                ans+=V[cur+1]+V[cur+2];
            }
            else{
                cur++;
                ans+=V[cur];
                if(V[cur-1]+V[cur]==10)ans+=V[cur+1];
            }
            cur++;
        }
        while(cur<V.size())ans+=V[cur++];
        R.push_back(pair<int,int>(ans,p));
    }
    sort(R.rbegin(),R.rend());

    for(int i=0;i<R.size();i++)printf("%d %d\n",R[i].second,R[i].first);
}

int main(){
    while(scanf("%d",&N),N)solve();
    return 0;
}

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