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 <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
int n;
bool sortrule(const pair<int,int> &p1,const pair<int,int> &p2)
{
  if(p1.first!=p2.first)
    {
      return p1.first>p2.first;
    }
  else
    {
      return p1.second<p2.second;
    }
}
int main(void)
{
  while(cin >> n && n)
    {
      set<int> st;
      st.clear();
      vector<pii> scores(10005);
      for(int i=0;i<=10000;i++)
	{
	  scores[i]=(pii(0,i));
	}
      vector<pair<int,int> > bowling[10005];
      for(int i=0;i<n;i++)
	{
	  //cout << "ID"<< endl;
	  int id;
	  cin >> id;
	  st.insert(id);
	  for(int j=0;j<10;j++)
	    {
	      
	      int fi=0,se=0,th=0;
	      cin >> fi;
	      if(j!=9 && fi==10) se=0;
	      else
		{
		  cin >> se;
		}
	      if(j==9 && ((fi==10) || (fi+se)==10))
		{
		  cin >> th;
		}
	      if(j!=9) bowling[id].push_back(pii(fi,se));
	      else 
		{
		  bowling[id].push_back(pii(fi,se));
		  scores[id].first+=(fi+se+th);
		}
	    }
	  for(int j=0;j<9;j++)
	    {
	      if(j!=8)
		{
		  int one=bowling[id][j].first;
		  int two=bowling[id][j].second;
		  int nxone=bowling[id][j+1].first;
		  int nxtwo=bowling[id][j+1].second;
		  int nxxone=bowling[id][j+2].first;
		  if(one+two<10)
		    {
		      scores[id].first+=(one+two);
		    }
		  else if(one!=10 && one+two==10)
		    {
		      scores[id].first+=(10+nxone);
		    }
		  else if(one==10)
		    {
		      if(nxone!=10)
			{
			  scores[id].first+=(10+nxone+nxtwo);
			}
		      else if(nxone==10)
			{
			  if(j<=8)
			    {
			      scores[id].first+=(10+nxone+nxxone);
			    }
			}
		    }
		}
	      else if(j==8)
		{
		  int one=bowling[id][j].first;
		  int two=bowling[id][j].second;
		  int nxone=bowling[id][j+1].first;
		  int nxtwo=bowling[id][j+1].second;
		  if(one+two<10)
		    {
		      scores[id].first+=(one+two);
		    }
		  else if(one!=10 && one+two==10)
		    {
		      scores[id].first+=(10+nxone);
		    }
		  else if(one==10)
		    {
		      if(nxone!=10)
			{
			  scores[id].first+=(10+nxone+nxtwo);
			}
		      else if(nxone==10)
			{
			  scores[id].first+=(10+nxone+nxtwo);
			}
		    }
		}
	      //cout << "Now ID score " << scores[i].second << ' ' << scores[id].first << endl;
	    }
	}
      sort(scores.begin(),scores.end(),sortrule);
      int cnt=0;
      for(int i=0;i<=10000;i++)
	{
	  if(cnt==n) break;
	  auto it=st.find(scores[i].second);
	  if(it!=st.end())
	    {
	      cnt++;
	      cout << scores[i].second << ' ' << scores[i].first << endl;
	    }
	}
    }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  for(int d;cin>>d,d;){
    vector<pair<int,int> > result;
    for(int i=0;i<d;i++){
      int name,score=0,a,b,k=0;
      cin>>name;
      for(int i=0;i<10;i++){
	cin>>a;score+=a;
	if(k&4) score+=a,k&=3;
	if(k&2) score+=a;
	if(k&1) score+=a,k&=6;
	if(a==10){
	  if(k&2)k|=4;
	  k|=2;
	}
	else{cin>>b;score+=b;
	  if(k&2)score+=b,k&=5;
	  if(a+b==10)k|=1;}
      }
      if(k&2){cin>>a>>b;score+=k&4?2*a+b:a+b;}
      if(k&1){cin>>a;score+=a;}
      result.push_back(mp(-score,name));
    }
    sort(result.begin(),result.end());
    for(int i=0;i<d;i++)cout<<result[i].second<<" "<<-result[i].first<<endl;
  }
}

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));
							data.push_back("l");
						}
					}
					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;
}