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

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

P 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++: #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=!cnt3;
      cnt2++;
      while(ste[cnt3])sum+=a,ste[cnt3]--;
      if(cnt2==1&&a==10) ste[cnt3]++,ste[!cnt3]++,cnt2=2;
      else if(cnt2==2&&a+pre==10) ste[!cnt3]++;
      pre=a;
      if(cnt2==2) cnt++,cnt2=0,pre=0;
      sum+=a;
    }

    if(ste[!cnt3]) cin>>a;
    while(ste[!cnt3]--)sum+=a;
    if(ste[cnt3]) cin>>a;
    while(ste[cnt3]--)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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int calc_score(vector<int> pins)
{
	int score = 0;
	int frame = 1;
	int frame_cnt = 1;
	int now = 0;

	rep(i,pins.size())
	{
		if (frame != 10)
		{
			if (frame_cnt == 1)
			{
				if (pins[i] == 10)
				{
					//????????¬????????????????????§??????????????????????????????
					score += 10;
					for (int j=i+1; j<=i+2 && j<pins.size(); j++)
						score += pins[j];
					frame++;
					frame_cnt = 1;	
					continue;
				} else {
					score += pins[i];
					frame_cnt++;
					continue;
				}
			} else if (frame_cnt == 2) {
				if (pins[i-1] + pins[i] == 10)
				{
					//????????¢???????????????
					score += pins[i];
					score += pins[i+1];
					frame++;
					frame_cnt = 1;
					continue;
				} else {
					score += pins[i];
					frame++;
					frame_cnt = 1;
					continue;
				}
			}
		} else if (frame == 10) {
			if (frame_cnt == 1)
			{
				if (pins[i] == 10)
				{
					score += 10;
					//for (int j=i+1; j<=i+2 && j<pins.size(); j++)
					//	score += pins[j];
					frame_cnt = 2;
					continue;
				} else {
					score += pins[i];
					frame_cnt = 2;
					continue;
				}
			} else if (frame_cnt == 2) {
				if (pins[i-1] == 10 && pins[i] == 10)
				{
					score += 10;
					//for (int j=i+1; j<=i+2 && j<pins.size(); j++)
					//	score += pins[j];
					frame_cnt = 3;
					continue;
				} else if (pins[i-1] + pins[i] == 10) {
					score += pins[i];
					//score += pins[i+1];
					frame_cnt = 3;
					continue;
				} else {
					score += pins[i];
					break;
				}
			} else if (frame_cnt == 3) {
				score += pins[i];
			}
		}
	}

	return score;
}

int m;
vector<int> ps;
pair<int, int> lst[100];

signed main()
{
	while (true)
	{
		cin >> m;
		if (m == 0) break;
		cin.ignore();
		string str;
		rep(i,m)
		{
			int num;
			ps.clear();

			getline(cin, str);
			//cout << "getline = " << str << endl;
			stringstream ss(str);

			ss >> num;
			//printf("num = %d\n", num);
			for (int x; ss >> x;)
			{
				ps.push_back(x);
			}

			lst[i] = make_pair(-calc_score(ps), num);
		}
	
		sort(lst, lst + m);

		rep(i,m)
		{
			cout << lst[i].second << " " << -lst[i].first << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
 
int main() {
  int n;
  while(cin >> n && n) {
    vector<P> a;
    a.resize(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].second*=-1;
      a[j].first=0;
      vector<int> b;
      int x;
      while(ss >> x) b.push_back(x);
      int i=0,k=0;
      vector<int> c;
      c.resize(b.size()+1);
      fill(c.begin(),c.end(),0);
      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++;
        if(i>=b.size()) break;
        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++;
      }
    }
    sort(a.rbegin(),a.rend());
    for(int i=0; i<n; i++) cout << -a[i].second << " " << a[i].first << endl;
  }
  return 0;
}