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>
using namespace std;

int main(void){
    // Your code here!
    while (true){
    int n,d=1,u=1,m=0,t=0,a,b;
    cin >> n;
    if (n==0) break;
    vector<int> id(n),s(n),dd(100000);
    for (int i=0;i<100000;i++){
        dd.at(i)=1;
    }
    for (int i=0;i<n;i++){
        cin >> id.at(i);
        t=0;u=1;m=0;d+=3;
        while (true){
            if (u<10){
            cin >> a;
            t=t+a;
            if (m==0 && t<10) {m++;d++;continue;}
            else if (t<10) {s.at(i)+=(t-a)*dd.at(d-1);s.at(i)+=a*dd.at(d);d++;t=0;u++;m=0;}
            else if (m==0 && t==10) {s.at(i)+=t*dd.at(d);dd.at(d+1)++;dd.at(d+2)++;t=0;u++;m=0;d++;}
            else {s.at(i)+=(t-a)*dd.at(d-1);s.at(i)+=a*dd.at(d);dd.at(d+1)++;t=0;u++;m=0;d++;}
            }
            if (u==10){
                cin >> a >> b;
                if (a+b>=10) {s.at(i)+=a*dd.at(d);s.at(i)+=b*dd.at(d+1);cin >> a;s.at(i)+=a;}
                else {s.at(i)+=a*dd.at(d);s.at(i)+=b*dd.at(d);}
                break;
            }
        }
    }
    vector<pair<int,int>> v(n);
    for (int i=0;i<n;i++){
        v.at(i).second=s.at(i);
        v.at(i).first=id.at(i);
    }
    sort(v.begin(),v.end(), [&](const pair<int, int>& x, const pair<int, int>& y) {
			if (x.second == y.second) {
				return x.first < y.first;
			}
			return x.second > y.second;
		});
    for (int i=0;i<n;i++) {
			cout << v[i].first << " " << v[i].second << endl;
		}
}
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<pair<int, int> > score;
    cin >>ws;
    for(int k=0; k<n; k++){
      vector<int> bowl;
      string s;
      int x = 0,sn,p=0;
      bool f = true;
      getline(cin,s);
      for(int i=0; i<s.size(); i++){
	if(s[i] == ' '){
	  if(f){sn = x;f = false;}
	  else{bowl.push_back(x);}
	  x = 0;
	}
	if(s[i]>='0' && s[i]<='9'){x = x*10+s[i]-'0';}
      }
      bowl.push_back(x);
      int a=0,b=0,c=0,d=0,e=2;
      for(int i=0; i<bowl.size(); i++){
	p+=bowl[i]*(a+1);
	d+=bowl[i];
	e--;
	a = b;
	b = 0;
	if(e == 1 && d == 10){
	  c++;
	  e = 2;
	  d = 0;
	  if(c<10){
	    a++;
	    b++;
	  }
	}
	if(e == 0){
	  c++;
	  e = 2;
	  if(d == 10 && c<10){a++;}
	  d = 0;
	}
      }
      score.push_back(make_pair(-p,sn));
    }
    sort(score.begin(),score.end());
    for(int i=0; i<score.size(); i++){
      cout<< score[i].second<<" "<<-score[i].first<<endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair <int,int> P;
int main(){
  int n;
  while(cin>>n,n){
  vector <P> ans;
  while(n--){
    int ID,sum=0,cnt=0,ste[2]={},cnt2=0,pre=0,a,cnt3=0;
    cin>>ID;
    while(cnt<10){
      cin>>a;
      cnt3++;
      cnt2++;
      while(ste[cnt3%2])sum+=a,ste[cnt3%2]--;
      if(cnt2==1&&a==10) ste[cnt3%2]++,ste[(cnt3+1)%2]++,cnt2=2;
      else if(cnt2==2&&a+pre==10) ste[(cnt3+1)%2]++;
      pre=a;
      if(cnt2==2) cnt++,cnt2=0,pre=0;
      sum+=a;
    }

    if(ste[cnt3%2]) cin>>a;
    while(ste[cnt3%2]--)sum+=a;
    if(ste[(cnt3+1)%2]) cin>>a;
    while(ste[(cnt3+1)%2]--)sum+=a;

    ans.push_back(P(sum,ID));
  }
  sort(ans.begin(),ans.end());
  for(int i=(int)ans.size()-1;i>=0;i--) cout << ans[i].second<<" "<<ans[i].first<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<int, string> Ps;

Ps data[40];
int cnt[11];
int main(){
  int m, a, b, c, score;
  while(cin >> m && m){
    rep(i, m){
      score = 0;

      fill(cnt, cnt + 10, 0);
      cin >> data[i].second;
      rep(j, 10){
	cin >> a;
	score += a;
	rep(k, 10) if(cnt[k] > 0){
	  cnt[k]--;
	  score += a;
	}

	if(a == 10){

	  if(j != 9)cnt[j]+=2;
	  else{
	    cin >> b >> c;
	    score += b + c;
	    rep(k, 10)if(cnt[k]){
	      cnt[k]--;
	      score += b;
	    }
	  }
	  
	}else{

	  cin >> b;
	  score += b;
	  rep(k, 10) if(cnt[k] > 0){
	    cnt[k]--;
	    score += b;
	  }
	  if(a + b == 10){
	    if(j != 9)cnt[j]++;
	    else{
	      cin >> c;
	      score += c;
	    }
	  }
	}
      }
      data[i].first = -score;
    }
    sort(data, data + m);
    rep(i, m){
      cout << data[i].second << " " << -data[i].first << endl;
    }
  }
  return 0;
}

C++: //17
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>

using namespace std;

struct IS{
  int i,s;
  bool operator<(IS a)const{
    if(s!=a.s){
      return s>a.s;
    }else{
      return i<a.i;
    }
  }
};

int main(){
  for(int m;cin>>m,m;){
    IS sc[40];
    cin.ignore();
    for(int i=0;i<m;i++){
      string s;
      getline(cin,s);
      stringstream ss(s);
      int id;
      ss>>id;
      int a[21]={};
      for(int j=0;ss>>a[j];j++);
      int scr=0;
      int x=0;
      for(int f=1;;f++){
	if(f!=10){
	  if(a[x]==10){
	    scr+=10+a[x+1]+a[x+2];
	    x++;
	  }else if(a[x]+a[x+1]==10){
	    scr+=10+a[x+2];
	    x+=2;
	  }else{
	    scr+=a[x]+a[x+1];
	    x+=2;
	  }
	}else{
	  scr+=a[x]+a[x+1]+a[x+2];
	  break;
	}
      }
      IS cs={id,scr};
      sc[i]=cs;
    }
    sort(sc,sc+m);
    for(int i=0;i<m;i++){
      cout<<sc[i].i<<' '<<sc[i].s<<endl;
    }
  }
  return 0;
}