Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw 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
	}

	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}
		}
		OrderedBy(win, lose).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

C++: #include <iostream>
using namespace std;
int main()
{
        while(true){
                int n;
                char t;
                int r;
                char x[10];
                cin >> n;
                if(n==0)
                        break;
                int win[10],lose[10];
                for(int i=0 ;i<10 ;i++){
                                win[i] = 0;
                                lose[i] = 0;
                }
                for(int i=0 ;i<n ;i++){
                        cin >> t;

                        for(int j=1 ;j<n ;j++){
                                cin >> r;
                                if(r==0){
                                        win[i]++;
                                }
                           if(r==1){
                                        lose[i]++;
                                }

                        }
                        x[i] = t;
                }
                char y=0,z=0;
                for(int i=0 ;i<n-1 ;i++){
                                for(int j=i+1 ;j<n ;j++){
                                if(win[i] < win[j]){
                                        z=win[i];
                                        win[i]=win[j];
                                        win[j]=z;
                                        y=x[i];
                                        x[i]=x[j];
                                        x[j]=y;
                                }
                                else if(win[i] == win[j]){
                                        if(lose[i] > lose[j]){
                                                z=win[i];
                                                win[i]=win[j];
                                                win[j]=z;
                                                y=x[i];
                                                x[i]=x[j];
                                                x[j]=y;
                                        }
                                }
								else if(win[i] == win[j] && lose[i] == lose[j]){
									if(x[i] <x[j]){
										y=x[i];
                                        x[i]=x[j];
                                        x[j]=y;
									}
								}
                        }
                }

                for(int i=0 ;i<n ;i++){
                        cout << x[i] << endl;
                }
        }
		return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct data{
    int w,l,p;
    char name;
    data(int a,int b,int c,char d):w(a),l(b),p(c),name(d){}
    data(){}
    bool operator<(const data &d)const{
        if(w!=d.w)return w<d.w;
        if(l!=d.l)return l>d.l;
        return p<d.p;
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        vector<data>V;
        for(int i=0;i<n;i++){
            char c;
            scanf(" %c",&c);
            int w,l;
            w=l=0;
            for(int j=0;j<n-1;j++){
                int val;
                scanf("%d",&val);
                if(val==2)continue;
                if(val)w++;
                else l++;
            }
            V.push_back(data(w,l,i,c));
        }
        sort(V.begin(),V.end());
        for(int i=0;i<n;i++){
            printf("%c\n",V[i].name);
        }

    }
    return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	char name;
	int win{0},draw{0},lose{0};
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true){
		int N=in();
		if(!N) break;

		vector<Data> T(N);
		REP(i,N){
			T[i].name=in<char>();
			REP(j,N-1){
				int v=in();
				if(!v) T[i].win++;
				else if(v==1) T[i].lose++;
				else T[i].draw++;
			}
		}
		sort(ALL(T),[](Data& l,Data& r){return l.win==r.win?l.lose<r.lose:l.win>r.win;});
		REP(i,N){
			out(T[i].name);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vector<string> t(n);
    pair<pii,int> p[10];
    rep(i,n){
      int r;
      cin>>t[i];
      p[i].second=i;
      rep(j,n-1){
        cin>>r;
        if(r==0)
          p[i].first.first--;
        else if(r==1)
          p[i].first.second++;
      }
    }
    sort(p,p+n);
    rep(i,n)
      cout<<t[p[i].second]<<endl;
  }
}