Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"sort"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw, Index int
}
type lessFunc func(p1, p2 *Team) bool
type multiSorter struct {
	teams []Team
	less    []lessFunc
}
func (ms *multiSorter) Sort(teams []Team) {
	ms.teams = teams
	sort.Sort(ms)
}
func OrderedBy(less ...lessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}
func (ms *multiSorter) Len() int {
	return len(ms.teams)
}
func (ms *multiSorter) Swap(i, j int) {
	ms.teams[i], ms.teams[j] = ms.teams[j], ms.teams[i]
}
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.teams[i], &ms.teams[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() {
	win := func(c1, c2 *Team) bool {
		return c1.Win > c2.Win
	}
	lose := func(c1, c2 *Team) bool {
		return c1.Lose < c2.Lose
	}
	index := func(c1, c2 *Team) bool {
		return c1.Index < c2.Index
	}

	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		teams := make([]Team, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			name := buf[0]
			tmp := make([]int, n-1)
			for i := range tmp {
				tmp[i], _ = strconv.Atoi(buf[i+1])
			}
			cntwin, cntlose, cntdraw := 0, 0, 0
			for _, v := range tmp {
				switch v {
				case 1:
					cntlose++
				case 0:
					cntwin++
				case 2:
					cntdraw++
				}
			}
			teams[i] = Team{name, cntwin, cntlose, cntdraw, i}
		}
		OrderedBy(win, lose, index).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,j,h,w[10],l[10],t,u[10];
	char q[11],g;
	while(1){
		for(i=0;i<10;i++){
			w[i]=0;
			l[i]=0;
		}	
		scanf("%d",&n);
		if(n<2) break;
			for(i=0;i<n;i++){
				u[i]=i;
				scanf(" %c",&q[i]);
				for(j=0;j<n-1;j++){
					scanf("%d",&h);
					if(h==0){
						w[i]++;
					}
					if(h==1){
						l[i]++;
					}
				}
			}
			for(i=0;i<n-1;i++){
				for(j=i+1;j<n;j++){
					if(w[i]<w[j]||(w[i]==w[j]&&l[i]>l[j])||(w[i]==w[j]&&l[i]==l[j]&&u[i]>u[j])){
						t=w[i];
						w[i]=w[j];
						w[j]=t;
						
						t=l[i];
						l[i]=l[j];
						l[j]=t;
						
						t=u[i];
						u[i]=u[j];
						u[j]=t;
					
						g=q[i];
						q[i]=q[j];
						q[j]=g;
					}				
				}	
			}		
			for(i=0;i<n;i++){			
				printf("%c\n",q[i]);
			}
	}
	return 0;
}

C++: #include<iostream>
#include<utility>
#include<algorithm>
#include<queue>
using namespace std;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		float r, w, f;
		priority_queue<pair<float,char>> results;
		for (int i = 0; i < n;++i) {
			cin >> name;
			w = 0.0, f = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				cin >> r;
				if (r == 0)w++;
				if (r == 1)f++;
			}
			f /= 1000.0;
			float result = w - f;
			results.push(make_pair(result,name));
		}
		for (int i = 0; i < n; ++i) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long int i,j,k,n,a,b,sum;
	while(1) {
		cin>>n;
		vector<pair<long long int,char> > pp(n);
		
		if(n==0) break;
		for(i=0;i<n;i++) {
			cin>>pp[i].second;
			sum=0;
			for(j=0;j<n-1;j++) {
				cin>>a;
				if(a==0) sum+=10000000;
				if(a==1) sum-=1;
			}
			pp[i].first=sum;
		}
		sort(pp.begin(),pp.end());
		for(i=n-1;i>=0;i--) {
			cout<<pp[i].second<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct data{
    char name;
    int win;
    int lose;
};

int main(){
    int n;
    struct data data[15];
    while(cin >> n, n){
        rep(i,n){
            cin >> data[i].name;
            data[i].win = data[i].lose = 0;
            rep(j,n - 1){
                int inp;
                cin >> inp;
                if(inp == 0)
                    data[i].win++;
                else if(inp == 1)
                    data[i].lose++;
            }
        }
        rep(i,n){
            rep(j,n - 1){
                if(data[j].win < data[j + 1].win){
                    struct data g = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = g;
                }
                if(data[j].win == data[j + 1].win){
                    if(data[j].lose > data[j + 1].lose){
                        struct data g = data[j];
                        data[j] = data[j + 1];
                        data[j + 1] = g;
                    }
                }
            }
        }
        rep(i,n){
            cout << data[i].name << endl;
        }
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
struct team{
	char name;
	int win,lose,draw;
	team(){
		win = lose = draw = 0;
	}
};
bool checker(team a,team b){
	if(a.win > b.win) return true;
	if(a.win == b.win && a.lose < b.lose) return true;
	return false;
}
int main(){
	int n,a;
	char b;
	while(cin >> n,n){
		team c[10];
		for(int i = 0;i < n;++i){
			cin >> b;
			c[i].name = b;
			for(int j = 0;j < n - 1;++j){
				cin >> a;
				if(a == 0) ++c[i].win;
				else if(a == 1) ++c[i].lose;
				else ++c[i].draw;
			}
		}
		sort(c,c+n,checker);
		for(int i = 0;i < n;++i){
			cout << c[i].name << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

struct st {
	char a;
	int b, c;
};
int main() {
	int n;
	while (cin >> n, n) {
		vector<st>v;
		rep(i, n) {
			char t; int a = 0, b = 0;
			cin >> t;
			rep(j, n - 1) {
				int r; cin >> r;
				if (!r)a++;
				if (r == 1)b++;
			}
			v.push_back({ t,a,b });
		}
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.c < b.c; });
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.b > b.b; });
		for (st i : v) {
			cout << i.a << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<char,pair<int,int> > p;
int main() {
	int n;
	while(cin>>n,n){
		vector<p>a;
		for(int i=0;i<n;i++){
			p data;cin>>data.first;
			data.second.first=0;
			data.second.second=0;
			for(int j=0;j<n-1;j++){
				int p;cin>>p;
				if(p==0)data.second.first++;
				else if(p==1)data.second.second++;
			}
			a.push_back(data);
		}
		for(int i=0;i<n;i++){
			int f=0;
			for(int j=1;j<a.size();j++){
				if(a[j].second.first>a[f].second.first)f=j;
				else if(a[j].second.first==a[f].second.first&&a[j].second.first<a[f].second.first)f=j;
			}
			cout<<a[f].first<<endl;
			v.erase(v.begin()+f);
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
typedef pair<P, char> Pc;

int main() {
    int N;
    while (cin >> N, N) {
        vector<Pc> pc;
        for (int i = 0; i < N; i++) {
            char c;
            cin >> c;
            int a = 0, b = 0;
            for (int j = 0; j < N - 1; j++) {
                int t; cin >> t;
                if (t == 0) a++;
                if (t == 2) b++;
            }

            pc.push_back(Pc(P(a, b), c));
        }

        sort(pc.begin(), pc.end());

        for (int i = 0; i < N; i++)
            cout << pc[N-1-i].second << endl;
    }

    return 0;
}