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<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[11],f[11],g,h,i,j,q[11];
	char z[11][11],x[11];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
		d[i]=0;
		f[i]=0;
		q[i]=i;
			scanf("%s",z[i]);
			for(j=0;j<a-1;j++){
				scanf("%d",&s);
				if(s==0) d[i]++;
				if(s==1) f[i]++;
			}
		}
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(d[i]<d[j]){
					g=q[i];
					q[i]=q[j];
					q[j]=g;
					g=d[i];
					d[i]=d[j];
					d[j]=g;
					h=f[i];
					f[i]=f[j];
					f[j]=h;
					strcpy(x,z[i]);
					strcpy(z[i],z[j]);
					strcpy(z[j],x);
				}
				else if(d[i]==d[j]){
					if(f[i]>f[j]){
						g=q[i];
						q[i]=q[j];
						q[j]=g;
						g=d[i];
						d[i]=d[j];
						d[j]=g;
						h=f[i];
						f[i]=f[j];
						f[j]=h;
						strcpy(x,z[i]);
						strcpy(z[i],z[j]);
						strcpy(z[j],x);
					}
					else if(f[i]==f[i]){
						if(q[i]>q[j]){
							g=q[i];
							q[i]=q[j];
							q[j]=g;
							g=d[i];
							d[i]=d[j];
							d[j]=g;
							h=f[i];
							f[i]=f[j];
							f[j]=h;
							strcpy(x,z[i]);
							strcpy(z[i],z[j]);
							strcpy(z[j],x);
						}
					}
				}
			}
		}
		for(i=0;i<a;i++) printf("%s\n",z[i]);
	}
	return 0;
}

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

bool large(pair<char, int> t1, pair<char, int> t2){
	return (t1.second > t2.second);
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		pair<char, int> teams[10];
		for(int i = 0;i < n;i++){
			cin >> teams[i].first;
			teams[i].second = 0;
			for(int j = 0;j < n - 1;j++){
				int r;
				cin >> r;
				if(r == 0) teams[i].second++;
				else if(r == 1) teams[i].second--;
			}
		}
		stable_sort(teams, teams + n, large);
		for(int i = 0;i < n;i++){
			cout << teams[i].first << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n, a; pair<int, char> d[10];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> d[i].second; d[i].first = i;
			for (int j = 0; j < n - 1; j++) {
				scanf("%d", &a);
				if (a == 0) d[i].first -= 100;
				if (a == 1) d[i].first += 10;
			}
		}
		sort(d, d + n);
		for (int i = 0; i < n; i++) printf("%c\n", d[i].second);
	}
	return 0;
}

C++: #include <iostream>   
using namespace std;   
  
int main()   
{   
    int n;   
    while (cin >> n, n)   
    {   
        char name[10];   
        int win[10] = {0};   
        int lose[10] = {0};   
  
        for (int i = 0; i < n; ++i)   
        {   
            cin >> name[i];   
            for (int j = 0; j < n - 1; ++j)   
            {   
                int s;   
                cin >> s;   
                if (s == 0)   
                    win[i]++;   
                if (s == 1)   
                    lose[i]++;   
            }   
        }   
  
        for (int i = n - 1; i > -1; --i)   
            for (int j = 0; j < n - i; ++j)   
                for (int k = 0; k < n; ++k)   
                    if (win[k] == i && lose[k] == j)   
                        cout << name[k] << endl;   
  
    }   
  
    return 0;   
}

C++: // #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
int INPUT_INT() {int d;cin>>d;return d;} // 入力をpush_back(d)やarray[d]に使う時に無駄な変数を使わない

// ------------------- include, typedef, define END. -------------------

void solveAndOutput(MuMAPIC &result){
	foreach_it(MuMAPIC, it, result){
		cout << (*it).second << endl;
	}
}

int main(){
	/* 方針
	 * A:381 , B:370 , C:40 , ...
	 * 百の位は勝ち数, 十の位は(9-負け数), 一の位は引き分け数.
	 * 入力チーム数が10以下（= 繰り上がり繰り下がりがないこと）を前提としている.
	 *
	 * また, 勝ち, 負け以外に引き分けしかない(無効試合とかない)ことを前提に, 引き分け数も計算に入れた.
	 */
	// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1167731
	// このコードは、↑のコードを、ビット演算使用してみたversionに書き換えたものである.

	int n = 0;
	char in_char;
	while (cin >> n, n){
		MuMAPIC result;

		// 各team入力
		FOR(teamSum, 0, n){
			// seisekiCount[0] = win, [1]=lose, [2]=hikiwake
			VI seisekiCount(3, 0);
			int temp_mapin = 0;

			cin >> in_char;
			FOR(i, 0, n - 1)
				seisekiCount[INPUT_INT()]++;

			//temp_mapin = seisekiCount[0] * 100 + (9 - seisekiCount[1]) * 10 + seisekiCount[2];
			FOR(i, 0, seisekiCount.size()){
				if (i == 1)
					temp_mapin += 9 - seisekiCount[i];
				else
					temp_mapin += seisekiCount[i];
				temp_mapin <<= 1;
			}
			result.insert(MP(temp_mapin, in_char));
		}
		// all teams input END.
		solveAndOutput(result);
	}
	return 0;
}