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
	}
	draw := func(c1, c2 *Team) bool {
		return c1.Draw < c2.Draw
	}

	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>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

typedef pair<int, int> pp;
typedef pair<pp, int> ppp;
typedef pair<ppp, char> pppp;

const int W = 0, L = 1;

int main()
{
    int n;
    while(cin >> n && n)
    {
        vector<pppp> ans;
        REP(n)
        {
            int w = 0, l = 0, r = 0;
            char t; cin >> t;
            rep(j,n- 1)
            {
                cin >> r;
                if(r == W) w++;
                if(r == L) l++;
            }
            ans.push_back(pppp(ppp(pp(-w, l),i), t));
        }
        sort(all(ans));

        REP(n) cout << ans[i].second << endl;
    }
    return 0;
}

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;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<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	tuple<int, int, int, string> t[10];
	for (int n; cin >> n&&n;) {
		rep(h, 0, n) {
			string s; cin >> s;
			int w = 0, l = 0;
			rep(i, 0, n - 1) {
				int r; cin >> r;
				if (r == 0)w++;
				if (r == 1)l++;
			}
			t[h] = make_tuple(-w, l, h, s);
		}
		sort(t, t + n);
		rep(i, 0, n) {
			cout << get<3>(t[i]) << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef struct{
  int num;
  char name;
  int win;
  int lose;
  int drow;
}TEAM;
main(){
  int n;
  TEAM team[15];
  while(1){
    cin>>n;
    if(n==0){
      break;
    }
    for(int i=0;i<n;i++){
      cin>>team[i].name;
      team[i].win=0;
      team[i].lose=0;
      team[i].drow=0;
      team[i].num=i;
      int a;
      for(int j=0;j<n-1;j++){
	cin>>a;
	if(a==0){
	  team[i].win++;
	}
	else if(a==1){
	  team[i].lose++;
	}
	else{
	  team[i].drow++;
	}
      }
    }
    for(int i=1;i<n;i++){
      for(int j=i;j>0;j--){
	if(team[j].win>team[j-1].win||(team[j].win==team[j-1].win&&team[j].lose<team[j-1].lose)||(team[j].win==team[j-1].win&&team[j].lose==team[j-1].lose&&team[j].num<team[j-1].num)){
	  TEAM temp;
	  temp=team[j];
	  team[j]=team[j-1];
	  team[j-1]=temp;
	}
      }
    }
    for(int i=0;i<n;i++){
      cout<<team[i].name<<endl;
    }
  }
}

C++: #include<stdio.h>
int main(void){
	int n,r,t[3][10],i,a,f;
	char N[10][10];
	scanf("%d",&n);
	for(i=0;i!=n;i++){
		t[0][i]=i;
		t[1][i]=0;
		t[2][i]=0;
	}
	for(i=0;i!=n;i++){
		scanf("%s",&N[i]);
		for(a=0;a!=n-1;a++){
			scanf("%d",&r);
			if(r==0){
				t[1][i]++;
			}
			else if(r==1){
				t[2][i]++;
			}
		}
	}
	for(i=0;i!=n;i++){
		for(a=i;a!=n;a++){
			if(t[1][i]<t[1][a]){
				for(f=0;f!=3;f++){
					r=t[f][i];
					t[f][i]=t[f][a];
					t[f][a]=r;
				}
			}
			else if(t[1][i]==t[1][a]){
				if(t[2][i]>t[2][a]){
					for(f=0;f!=3;f++){
						r=t[f][i];
						t[f][i]=t[f][a];
						t[f][a]=r;
					}
				}
			}
		}
	}
	for(i=0;i!=n;i++){
		r=t[0][i];
		printf("%s\n",N[r]);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,sum[10];
	int data;
	char name[10][2];
	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]-=1;
			}
		}
		
		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 <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        vector<pair<pair<int,int>, pair<int,char> > > res;
        for (int i=0; i<n; ++i) {
            char t;
            cin >> t;
            int r, win = 0, lose = 0;
            for (int j=0; j<n-1; ++j) {
                cin >> r;
                if (r == 0) ++ win;
                else if (r == 1) ++ lose;
            }
            res.push_back(make_pair(make_pair(-win, lose), make_pair(i, t)));
        }
        sort(res.begin(), res.end());
        for (int i=0; i<(int)res.size(); ++i) {
            cout << res[i].second.second << endl;
        }
    }
    return 0;
}