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<cstdio>
#include<string>
#define INITIAL 0
using namespace std;
struct comewith {
int ID;
int SCORE;
};
int BOWLINGSCORE(int h[22]){
int NEXT=INITIAL,total=INITIAL;
if (h[1]<10){    //1
        total+=h[1]+h[2];
        if (h[1]+h[2]==10){
                total+=h[3];
        }
        NEXT=3;
}
else {
        total+=h[1]+h[2]+h[3];
        NEXT=2;
}
if (h[NEXT]<10){    //2
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){     //3
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){    //4
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){    //5
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){    //6
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){    //7
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){    //8
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){    //9
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
        NEXT+=2;
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
        NEXT+=1;
}
if (h[NEXT]<10){    //10
        total+=h[NEXT]+h[NEXT+1];
        if (h[NEXT]+h[NEXT+1]==10){
                total+=h[NEXT+2];
        }
}
else {
        total+=h[NEXT]+h[NEXT+1]+h[NEXT+2];
}
return total;
}
int main (void){
comewith result[40]={INITIAL};
int m,grad=INITIAL,s=INITIAL,o=INITIAL, h[1/* ← ID */+21],hc[22],b=INITIAL;
        scanf("%d\n",&m);
        for (int i=0;i<m;i++){
                scanf ("%d",&h[0]);  //ID input
   for (int sc=1;sc<=21;sc=sc+2){
    scanf ("%d",&h[sc]);
    if (h[sc]<10){
     scanf ("%d",&h[sc+1]);
    }
    else {
     h[sc+1]=0;
    }
    if (sc==21&&h[sc-1]+h[sc-2]==10){
     scanf ("%d",&h[sc]);
    }
    else {
     h[sc]=0;
    }
                        }
   for (int sc=0;sc<=21;sc++){
    if (h[sc]!=0){
     hc[b]=h[sc];
     b++;
    }
   }
                        int ret=BOWLINGSCORE(h);
                            result[grad].ID=h[INITIAL];
                            result[grad].SCORE=ret;
                            grad++;
        }
        for (int i=0;i<m;i++){
                for (int j=i+1;j<m;j++){
                        if (result[i].SCORE<result[j].SCORE){
                                comewith tmp=result[i];
                                    result[i]=result[j];
                                    result[j]=tmp;
                        }
                }
        }
        while (1){
                if (s>m){
                        if (o==0){
                                break;
                        }
                        s=0;
                        }
                if (result[s].SCORE==result[s+1].SCORE){
                        if(result[s].ID>result[s+1].ID){
                                int tmp=result[s].ID;
                                    result[s].ID=result[s+1].ID;
                                    result[s+1].ID=tmp;
                                    o++;
                        }
                }
        s++;
        }
        for (int i=0;i<m;i++){
                cout<<result[i].ID<<" "<<result[i].SCORE<<endl;
        }
return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<int> stovi(string s){
    vector<int> ret;
    int t=0;
    for (int i = 1; i < s.size(); ++i) {
        if(isdigit(s[i])){
            t=t*10;
            t+=s[i]-'0';
        }
        else {
            ret.emplace_back(t);
            t=0;
        }
    }
    ret.emplace_back(t);
    return ret;
}

int calscore(string s){
    vector<int> scores=stovi(s);
    int ret=0;
    int flame=1;
    bool first=true;
    bool spare=false;
    bool strike=false;
    bool strike2=false;
    for (int i = 0; i < scores.size(); ++i) {
        ret+=scores[i];
        if(spare)ret+=scores[i];
        if(strike)ret+=scores[i];
        if(strike2)ret+=scores[i];
        strike2=strike;
        strike=false;
        spare=false;
        if(first){
            if(flame!=10&&scores[i]==10){
                strike=true;
                ++flame;
            }
            else first=false;
        }
        else{
            if(flame!=10&&scores[i]+scores[i-1]==10)spare=true;
            first=true;
            ++flame;
        }
    }
    return ret;
}

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<pair<int,int>> sc;
        for (int i = 0; i < n; ++i) {
            int id;
            string s;
            cin>>id;
            getline(cin,s);
            sc.emplace_back(calscore(s),-id);
        }
        sort(sc.rbegin(),sc.rend());
        for(auto i:sc)cout<<-i.second<<" "<<i.first<<endl;
    }
    return 0;
}