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

int main(){
  int m;
  while(cin >> m, m){
    vector<string> I(m);
    vector<int> S(m,0);
    for(int i = 0; i < m; ++i){
      cin >> I[i];
      vector<int> t;
      for(int j = 0; j < 20; ++j){
        int s;
        cin >> s;
        if(j < 18 and s == 10) ++j;
        t.push_back(s);
      }
      if(t[t.size()-1]+t[t.size()-2] >= 10){
        int s;
        cin >> s;
        t.push_back(s);
      }
      int l = 0;
      for(size_t j = 0; j < t.size(); ++j){
        int tmp = t[j], k = 0;
        ++l;
        if(tmp < 10 and j+1 < t.size()) tmp += t[++j], ++k;
        if(l < 10 and tmp == 10){
          if(j+1 < t.size()) S[i] += t[j+1];
          if(k == 0 and j+2 < t.size()) S[i] += t[j+2];
        }
        S[i] += tmp;
      }
      
    }
    vector<pair<int,string>> V;
    for(int i = 0; i < m; ++i)
      V.emplace_back(-S[i],I[i]);
    sort(V.begin(), V.end());
    for(auto p : V)
      cout << p.second << " " << -p.first<< endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

typedef pair<int,int> P;

vector<int> Point(string s){
  stringstream ss(s);
  int num;
  vector<int> v;

  while(ss >> num){
    v.push_back(num);
  }

  return v;
}

int getScore(string s){
  vector<int> a = Point(s);
  int len = (int)a.size();
  int score = 0 , sum = 0;
  int plus[10] = {0};
  int p = 0,n = 0;

  for(int i = 0 ; i < len ; i++){
    if(p >= 9){
      p++;
      score += a[i];
    }else{
      if(a[i] == 10){
	score += a[i];
	plus[p++] = a[i+1] + a[i+2];
      }else{
	n++;
	sum += a[i];
	if(n == 2){
	  n = 0;
	  score += sum;
	  if(sum == 10){
	    plus[p++] = a[i+1];
	  }else{
	    p++;
	  }
	  sum = 0;
	}
      }
    }
  }

  for(int i = 0 ; i < 10 ; i++){
    score += plus[i];
  }

  return -score;
}

int main(){
  int m;
  while(cin >> m ,m){
    vector<P> v;
    string pin;
    for(int i = 0 ; i < m ; i++){
      int score = 0,num;
      cin >> num;
      getline(cin,pin);
      score = getScore(pin);
      v.push_back(P(score,num));
    }
    sort(v.begin(),v.end());
    for(int i = 0 ; i < m ; i++){
      cout << v[i].second << " " << -v[i].first << endl;
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
typedef pair<int,string > mmp;

int main(){
	while(1){
		string nn;
		getline(cin,nn);
	//	cout<<nn<<endl;
		if(nn[0]=='0')break;
		int n=0;
		for(int i=0;i<nn.size();i++){
			n*=10;
			n+=nn[i]-'0';
		}
		if(n==0)break;
		vector<mmp> user(n);
		for(int j=0;j<n;j++){
			string line ;
			getline(cin,line);
	//		cout<<j<<' '<<line<<endl;
			string name;
	
			vector<int> s;
			int i;
			int st= 0;
			for( i=0;i<line.size();i++){
				if(line[i]==' ')break;
				name = name+line[i];
				st = i;
			}
			int sum = 0;
		//	cout<<name<<endl;
			i++;
			//cout<<"next"<<line[st+2]<<endl;
			for(i = st+2 ;i<line.size();i++){
			//	cout<<i<<' '<<line[i]<<endl;
				if(line[i]==' '){
					s.push_back(sum);
					//cout<<sum<<endl;
			//		cout<<i<<line[i]<<sum<<endl;
					sum = 0;
					continue;
				}
				sum*=10;
				sum+= line[i]-'0';
			}
			
			//for(int i=0;i<s.size();i++)cout<<s[i]<<endl;
			s.push_back(sum);
			vector<int> sc;
			int res = 0;
			int cnt = 0;
			for(int i=0;i<s.size()&&cnt<10;i++){
				if(s[i]==10){
					res+=s[i]+s[i+1]+s[i+2];
					cnt++;
				}else{
					int tmp = s[i]+s[i+1];
					if(tmp==10)tmp+=s[i+2];
					res+=tmp;
					i++;
					cnt++;
				}
			}
			user[j] = mmp(-res,name);
			
		}

	//	cout<<"ok "<<n<<endl;
		sort(user.begin(),user.end());
		for(int i=0;i<n;i++)cout<<user[i].second<<' '<<-user[i].first<<endl;
		//break;


	}


	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long n,i,j,s[40],p[21],q[40],t;
while(cin>>n,n){
for(i=0;i<n;i++){
cin>>s[i];
q[i]=0;
for(j=0;j<20;j++){
cin>>p[j];
q[i]+=p[j];
if(j<18&&j%2==0&&p[j]==10){j++;p[j]=0;}
}
if(p[18]==10||p[18]+p[19]==10){cin>>p[20];q[i]+=p[j];}
for(j=0;j<18;j+=2){
if(p[j]==10){
if(p[j+2]==10)q[i]+=p[j+2]+p[j+4];
else q[i]+=p[j+2]+p[j+3];
}else if(p[j]+p[j+1]==10){
q[i]+=p[j+2];
}
}
}
for(i=n-1;i>=1;i--){
for(j=0;j<i;j++){
if(q[j]<q[j+1]||q[j]==q[j+1]&&s[j]>s[j+1]){
t=q[j];q[j]=q[j+1];q[j+1]=t;
t=s[j];s[j]=s[j+1];s[j+1]=t;
}
}
}
for(i=0;i<n;i++){
cout<<" "<<s[i]<<" "<<q[i]<<endl;
}
}
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    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;
      int c[b.size()];memset(c,0,sizeof(c));
      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,a+n,greater<P>());
    for(int i=0; i<n; i++) cout << a[i].second << " " << a[i].first << endl;
  }
  return 0;
}