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++: //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;
}

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[30][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%*c", &m), m) {
		vector<P>v;
		rep(i, m) {
			memset(s, -1, sizeof(s));
			string S; getline(cin, S);
			stringstream buf(S);
			int id; buf >> id;
			int f = 1; bool b = 0;
			while (f <= 9) {
				buf >> s[f][b];
				if (s[f][b] == 10)f++;
				else {
					if (b)f++;
					b = !b;
				}
			}
			buf >> s[10][0] >> s[10][1];
			if (s[10][0] == 10 || s[10][1] == 10 || s[10][0] + s[10][1] == 10)buf >> s[10][2];
			int k;
			if (buf >> k)abort();
			P p(1, 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;
			for (int i = 1; i <= 10; i++)rep(j, 3) {
				if (~s[i][j])cnt += s[i][j];
			}
			v.push_back(P(cnt, id));
		}
		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 <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<pair<int,int> > v;
		rep(i,n)
		{
			
			vector<pair<int,int> > temp;
			vector<string> data;
			int num;
			cin >> num;
		
			int cnt = 0;
			while(cnt != 10)
			{
				int a,b,last;
				cin >> a;

				if(a == 10)
				{
					temp.push_back(make_pair(a,0));
					cnt++;
					data.push_back("st");

					if(cnt == 10)
					{
						int t;
						cin >> t;

						if(t == 10)
						{
							int t2;
							cin >> t2;
							temp.push_back(make_pair(t,0));
							data.push_back("st");

							temp.push_back(make_pair(t2,0));
							data.push_back("st");
							
						}
						else
						{
							int t2;
							cin >> t2;
							temp.push_back(make_pair(t,t2));
							if(t+t2 == 10) data.push_back("sp");
							else data.push_back("no");
						}
					}
				}
				else
				{
					cin >> b;
					temp.push_back(make_pair(a,b));
					cnt++;

					if(a + b == 10)
					{
						data.push_back("sp");
						
						if(cnt == 10)
						{
							int t;
							cin >> t;
							temp.push_back(make_pair(t,0));
							
							if(t == 10) data.push_back("st");
							else data.push_back("no");
						}
					}
					else
					{
						data.push_back("no");
					}
				}
			}
			
			int ans = 0;
			rep(i,10)
			{
				if(data[i] == "no")
				{
					ans += temp[i].first + temp[i].second;
				}
				else if(data[i] == "sp")
				{
					ans += temp[i].first + temp[i].second + temp[i+1].first;
				}
				else if(data[i] == "st")
				{
					ans += temp[i].first + temp[i].second + temp[i+1].first + temp[i+1].second;
					if(data[i+1] == "st") ans += temp[i+2].first;
				}
			}	
			v.push_back(make_pair(ans,num));
		}

		sort(v.begin(),v.end(),greater<pair<int,int> >());

		rep(i,v.size())
		{
			cout << v[i].second << " " << v[i].first << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int, int> P;
int main(){
	int n,a,psum,c,take,f;
	string str,out;
	P tmp,array[40];
	vector<P> plist;
	vector<int> point;
	while(cin >> n,n){
		plist.clear();
		getline(cin,str);
		for(int i = 0;i < n;++i){
			psum = c = take = 0;
			getline(cin,str);
			stringstream buf(str);
			point.clear();
			f = 1;
			while(buf >> out){
				a = atoi(out.c_str());
				if(f) {
					tmp.second = a;
					f = 0;
				}
				else{
					point.push_back(a);
				}
			}
			int k = 0;
			for(int j = 0;j < 10;++j){
				if(point[k] == 10){
					psum += point[k] + point[k + 1] + point[k + 2];
					++k;
				}
				else if(point[k] + point[k + 1] == 10){
					psum += point[k] + point[k + 1] + point[k + 2];
					k += 2;
				}
				else{
					psum += point[k] + point[k + 1];
					k += 2;
				}
			}
			tmp.first = psum;
			plist.push_back(tmp);
			buf.clear();
		}
		sort(plist.begin(),plist.end());
		reverse(plist.begin(),plist.end());
		for(int i = 0;i < plist.size();++i){
			cout << plist[i].second << " " << plist[i].first << endl;
		}
	}
	return 0;
}