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<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,sum[11];
	int data;
	char name[11][11];
	while(1) {
		cin>>n;
		if(!n) break;
		for(i=0;i<n;i++) sum[i]=0;
		for(i=0;i<n;i++) {
			cin>>name[i];
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) sum[i]+=10000;
				else if(data==1) sum[i]-=10;
			}
		}
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				if(sum[i]>sum[j]) {
					swap(sum[i],sum[j]);
					swap(name[i],name[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<name[i]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

struct Team
{
	char name[2];
	int win;
	int lose;
};

class team_comparator
{
public:
	bool operator() (Team t1, Team t2)
	{
		if(t1.win != t2.win) return t1.win > t2.win;
		else return t1.lose < t2.lose;
	}
};

Team S[10];

int main(int argc, char** argv)
{
	int n, r;
	while(cin >> n, n)
	{
		for(int i=0; i<n; i++)
		{
			cin >> S[i].name;
			S[i].win = 0;
			S[i].lose = 0;
			for(int j=0; j<n-1; j++)
			{
				cin >> r;
				switch(r)
				{
					case 0:
						S[i].win++;
						break;
					case 1:
						S[i].lose++;
						break;
				}
			}
		}

		sort(&S[0], &S[n], team_comparator());

		for(int i=0; i<n; i++)
		{
			cout << S[i].name << endl;
		}
	}

	return 0;
}

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

struct t_team{
	char c;
	int w, l, d;
	t_team(){ c = w = l = d = 0; }
};
bool operator<( const t_team &l, const t_team &r ){
	if( l.w == r.w )
		return l.l < r.l;
	else
		return l.w > r.w;
}

int main(){
	int n;
	while( cin >> n, n ){
		t_team t[10];
		for(int i=0; i<n; i++){
			cin >> t[i].c;
			for(int j=0; j+1<n; j++ ){
				int k;
				cin >> k;
				if(k==0)	  t[i].w++;
				else if(k==1) t[i].l++;
				else		  t[i].d++;
			}
		}
		stable_sort( t, t+n );
		for(int i=0; i<n; i++){
			cout << t[i].c << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

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

int main(){
  int n;
  char name;
  P2 team[11];
  while(cin >> n, n){
    for(int i = 0 ; i < n ; i++){
      team[i].first = 0;
      team[i].second.first = 0;
    }
    
    int op;
    for(int i = 0 ; i < n ; i++){
      cin >>team[i].second.second;
      for(int j = 0 ; j < n-1 ; j++){
	cin >> op;
	if(op == 0) team[i].first++;
	if(op == 1) team[i].second.first++;
      }
    }
    
    for(int i = 0 ; i < n ; i++){
      team[i].second.first *= -1;
    }
    
    sort(team, team+n);
    reverse(team, team+n);
    
    for(int i = 0 ; i < n ; i++){
      cout << team[i].second.second << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n,r;pair<int,char>d[10];
int main(){
	  while (true) {
       cin>>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", &r);
                if (r == 0) d[i].first -= 100;
                if (r == 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++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	while (true) {
		int n; cin >> n;
		if (n == 0)break;

		// <<勝ち数, -負け数>, 入力順>, 名前
		vector<pair<pair<pair<int, int>, int>, string>> d(n);

		rep(i, n) {
			string name; cin >> name;
			int c0 = 0, c1 = 0, c2 = 0;
			rep(j, n - 1) {
				int x; cin >> x;
				switch (x) {
				case 0:
					c0++; break;
				case 1:
					c1++; break;
				case 2:
					c2++; break;
				}
			}

			d[i] = mp(mp(mp(-c0, c1), i), name);
		}

		sort(all(d));

		rep(i, n)Cout(d[i].second);
	}
}

C++: #include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    vector<tuple<char, int, int>> teams;
    while(cin >> n && n){
        teams.resize(n);
        for(int i = 0; i < n; i++){
            char team;
            cin >> team;
            int win = 0, lose = 0;
            for(int j = 0; j < n - 1; j++){
                int result;
                cin >> result;
                switch(result){
                case 0:
                    win++;
                case 1:
                    lose++;
                }
            }
            teams[i] = make_tuple(team, win, lose);
        }
        sort(begin(teams), end(teams), [](tuple<char, int, int> a, tuple<char, int, int> b){
            if(get<1>(a) != get<1>(b)){
                return get<1>(a) > get<1>(b);
            }else{
                return get<2>(a) < get<2>(b);
            }
        });
        for(auto&& i : teams){
            cout << get<0>(i) << "\n";
        }
    }
}