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 <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  while (cin >> n, n){
    pair<pair<int, int>, char> ppiic[11];
    for (int i = 0; i < n; i++){
      char c;
      ppiic[i].first = make_pair(0, 0);
      cin >> c;
      ppiic[i].second = c;
      for (int j = 0; j < n - 1; j++){
        int num;
        cin >> num;
        if (num == 0) ppiic[i].first.first++;
        else if (num == 1) ppiic[i].first.second--;;
      }
    }
    sort(ppiic, ppiic + n);
    reverse(ppiic, ppiic + n);

    for (int i  = 0; i < n; i++){
      cout << ppiic[i].second << '\n';
    }
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){

	int n;
	char t[10];
	int r;
	int win[10] = { 0 }, lose[10] = { 0 };

	while (cin >> n && n != 0){

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

		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				if (win[i] < win[j]){
					swap(win[i], win[j]);
					swap(lose[i], lose[j]);
					swap(t[i], t[j]);
				}
				else if (win[i] == win[j]){
					if (lose[i] > lose[j]){
						swap(win[i], win[j]);
						swap(lose[i], lose[j]);
						swap(t[i], t[j]);
					}
				}
			}

			cout << t[i] << endl;
		}
	}
}

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

typedef struct {
	char t;
	int pt[10];
	int win;
	int lose;
} GAME;

int main()
{
	GAME game[10], tmp;
	int n;

	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			game[i].win = game[i].lose = 0;
			cin >> game[i].t;
			for (int j = 0; j < n - 1; j++){
				cin >> game[i].pt[j];
				if (game[i].pt[j] == 0){
					game[i].win++;
				}
				else if (game[i].pt[j] == 1){
					game[i].lose++;
				}
			}
		}

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (game[j].win > game[j - 1].win){
					swap(game[j], game[j - 1]);
				}
				else if (game[j].win == game[j - 1].win && game[j].lose < game[j - 1].lose){
					swap(game[j], game[j - 1]);
				}
			}
		}

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

	return (0);
}

C++: //16
#include<iostream>
#include<algorithm>
#include<utility>

using namespace std;

typedef pair<char,int[3]> pci;

bool cmp(pci a,pci b){
  return a.second[0]>b.second[0]||(a.second[0]==b.second[0]&&a.second[1]<b.second[1]);
}				   

int main(){
  for(int n;cin>>n,n;){
    pci t[10];
    for(int i=0;i<n;i++){
      cin>>t[i].first;
      for(int j=0;j<n-1;j++){
	int r;
	cin>>r;
	t[i].second[r]++;
      }
    }
    stable_sort(t,t+n,cmp);
    for(int i=0;i<n;i++){
      cout<<t[i].first<<endl;
    }
  }
  return 0;
}

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+=2;
                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<stdio.h>
#include<string.h>
int main(void)
{
	char x[10],r;  
	int n,a[10],b[10],c[10],i,k,t;
	scanf("%d",&n);
	while(1){
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf(" %c",&x[i]);
			a[i]=0; b[i]=0; c[i]=i;
			for(k=0;k<n-1;k++){
				scanf("%d",&t);
				if(t==1) a[i]++;
				if(t==0) b[i]++;
			}
		}
		for(i=0;i<n-1;i++){
			for(k=i+1;k<n;k++){
				if((a[i]>a[k]) || (a[i]==a[k] && b[i]<b[k]) || (a[i]==a[k] && b[i]==b[k] && c[i]<c[k])){
					t=a[i]; a[i]=a[k]; a[k]=t;
					t=b[i]; b[i]=b[k]; b[k]=t;
					t=c[i]; c[i]=c[k]; c[k]=t;
					r=x[i]; x[i]=x[k]; x[k]=r;
				}
			}
		}
		for(i=0;i<n;i++) printf("%c\n",x[i]);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[100];
	int i,j,temp;
	int w[100],l[100],a[100];
	char t[100],m;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			w[i]=0;
			l[i]=0;
			scanf(" %c",&t[i]);
			for(j=0;j<n-1;j++){
				scanf("%d",&p[j]);
				if(p[j]==0){
					w[i]++;
				}
				if(p[j]==1){
					l[i]++;
				}
			}
		a[i]=i;
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(w[i]<w[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && a[i]>a[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%c\n",t[i]);
		}
		scanf("%d",&n);
	}
	return 0;
}