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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        vector<pii> ujimatsu(n,pii(0,0));
        vc anko(n);
        rep(i,n){
            cin>>anko[i];
            rep(j,n-1){
                int tiya; cin>>tiya;
                if(tiya==0)ujimatsu[i].first+=10000000000;
                else if(tiya==1)ujimatsu[i].second+=1;
                else if(tiya==2)ujimatsu[i].first+=1;
            }
        }
        vector<bool>flag(1000,true);
        rep(i,n){
            int maxi=-INF;
            int ans=0;
            rep(j,n){
                if(!flag[j])continue;
                if(ujimatsu[j].first>maxi){
                    maxi=ujimatsu[j].first;
                    ans=j;
                }else if(ujimatsu[j].first==maxi){
                    if(ujimatsu[ans].second>ujimatsu[j].second){
                        ans=j;
                    }
                }
            }
            flag[ans]=false;
            cout<<anko[ans]<<endl;
        }
    }
}

C++: #include<iostream>
#include<map>
#include<string>
#include<stdio.h>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
    int n,score,sum[10000],memo=0,max=-10000;
    char ch[10000],tem;
    while(1){
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>ch[i];
        for(int j=0;j<n-1;j++){
            cin>>score;
            if(score==0){
                memo+=1;
            }
            else if(score==1){
                memo-=1;
            }
        }
        sum[i]=memo;
        memo=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(sum[j]>max){
                max=sum[j];
                tem=ch[j];
                memo=j;
            }
        }
        cout<<tem<<endl;
        sum[memo]=-10000;
        max=-10000;
    }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(void){
	int n;
	while(cin>>n,n){
		multimap<int,string,greater<int> > ranking;
		for(int i=0;i<n;++i){
			string s;
			int win=0,lose=0;
			cin>>s;
			for(int j=0,score;j<n-1;++j){
				cin>>score;
				if(score==0) win++;
				else if(score==1) lose++;
			}
			ranking.insert(multimap<int,string>::value_type(win+n-1-lose,s));
		}
		multimap<int,string,greater<int> >::iterator it;
		for(it=ranking.begin();it!=ranking.end();++it){
			cout<<(*it).second<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


int main() {
	int n, a;
	string s;
	while (cin >> n && n > 0) {
		vector < pair<pii, pair<int, string> > > v(n,pair<pii,pair<int,string> >(pii(0,0),pair<int,string>(0,"")));
		rep(i, n) {
			cin >> s;
			v[i].second.first = i;
			v[i].second.second = s;
			rep(j, n - 1) {
				cin >> a;
				if (a == 0) {
					v[i].first.first -= 1;
				}
				else if (a == 1) {
					v[i].first.second += 1;
				}
			}
		}
		sort(all(v));
		rep(i, n) {
			cout << v[i].second.second << endl;
		}
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		pair<pair<int, int>, char> t[10];
		
		for (int i = 0; i < n; i++){
			t[i].first.first = t[i].first.second = 0;
			char name;
			scanf(" %c", &name);
			t[i].second = name;
			for (int j = 0; j < n - 1; j++){
				int x;
				scanf("%d", &x);
				if (x == 0) t[i].first.first--;
				if (x == 1) t[i].first.second++;
			}
		}
		
		sort(t, t + n);
		
		for (int i = 0; i < n; i++)
			printf("%c\n", t[i].second);
	}
}

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

using namespace std;

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

int main(){
  int n;
  P2 team[11];
  map<int, char> names;
  while(cin >> n, n){
    names.clear();
    for(int i = 0 ; i < n ; i++){
      team[i].first = 0;
      team[i].second.first = 0;
    }
    int cnt = 0;
    char name;
    int op;
    for(int i = 0 ; i < n ; i++){
      cin >> name;
      team[i].second.second = cnt;
      names.insert(make_pair(cnt++, name));
      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].first *= -1;
    }
    
    stable_sort(team, team+n);
    //reverse(team, team+n);
    
    for(int i = 0 ; i < n ; i++){
      cout << names[team[i].second.second] << endl;
    }
  }
  return 0;
}