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<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
int a[100000];
int n, sum, p;
char c[100000];
int main() {
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> c[i];
			sum = 0;
			for (int j = 0; j < n - 1; j++) {
				cin >> p;
				if (p == 0) { sum += 10000; }
				if (p == 2) { sum += 100; }
			}
			sum += (20 - i);
			a[i] = sum;
		}
		sort(a, a + n);
		for (int i = n - 1; i >= 0; i--) {
			cout << c[20 - (a[i] % 100)] << endl;
		}
	}
}

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]);
			a[i]=i;
			for(j=0;j<n-1;j++){
				scanf("%d",&p[j]);
				if(p[j]==0){
					w[i]++;
				}
				if(p[j]==1){
					l[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;
				}
				else if(w[i]==w[j] && l[i]>l[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;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

struct st {
	char a;
	int b, c;
};
int main() {
	int n;
	while (cin >> n, n) {
		vector<st>v;
		rep(i, n) {
			char t; int a = 0, b = 0;
			cin >> t;
			rep(j, n - 1) {
				int r; cin >> r;
				if (!r)a++;
				if (r == 1)b++;
			}
			v.push_back({ t,a,b });
		}
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.c < b.c; });
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.b > b.b; });
		for (st i : v) {
			cout << i.a << endl;
		}
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,string> PP;
int n,m;
PP t[10];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i].second;
      t[i].first.first=t[i].first.second=0;
      for(int j=0;j<n;j++){
	if(i==j)continue;
	cin>>m;
	if(m==0)t[i].first.first--;
	else if(m==1)t[i].first.second++;
      }
    }
    sort(t,t+n);
    for(int i=0;i<n;i++){cout<<t[i].second<<endl; 
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		char a[20];
		int b[20][2];
		bool l[20];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			b[i][0] = 0;
			b[i][1] = 0;
			l[i] = false;
			for (int j = 0; j < n - 1; j++) {
				int x;
				cin >> x;
				if (x == 0) b[i][0]++;
				else if (x == 1) b[i][1]++;
			}
		}
		for (int i = 0; i < n; i++) {
			int maxw = 100000,t=0;
			for (int j = n-1; j >= 0; j--){
				if (!l[j]) {
					if (maxw > b[j][0]) {
						t = j;
						maxw = b[j][0];
					}
					else if (maxw == b[j][0]) {
						if (b[t][1] >= b[j][1]) {
							t = j;
						}
					}
				}
			}
			l[t] = true;
			cout << a[t] << endl;
			maxw = -1;
		}
	}
}

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

using namespace std;
int i,j,make[100],kati[100];
char name[100];

void change(){
  int tmp1,tmp2;
  char tmp3;
  tmp1 = kati[i];
  kati[i] = kati[j];
  kati[j] = tmp1;
  
  tmp2 = make[i];
  make[i] = make[j];
  make[j] = tmp2;
  
  tmp3 = name[i];
  name[i] = name[j];
  name[j] = tmp3;
}

int main(){
  int n,s;
  while(1){
    cin >> n;
    if( n == 0 )break;
    for( i = 0;i < n ; i++){
      kati[i] = 0;
      make[i] = 0;
    }
    
    for( i = 0 ; i < n ; i++ ){
	cin >> name[i];
      for( j = 0; j < n-1 ; j++ ){
	cin >> s;
	if(s == 0)kati[i]++;
	if(s == 1)make[i]++;
      }
    }

    for( i = 0; i < n-1 ; i++){
      for( j = i+1; j < n ; j++){
	if(kati[i] < kati[j] ){
	  change();
      }
      }
    }
    //     for(i = 0;i < n ;i++)cout << name[i] << endl;

         for( i = 0; i < n-1 ; i++){
      for( j = i+1; j < n ; j++){

	if(( kati[i]==kati[j] )&&( make[i] > make[j] )){
	    change();
	  }
      }
      }
    
     for(i = 0;i < n ;i++)cout << name[i] << endl;
    
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,r,team[11],t;
	char name[11],T;
	while(1){
		for(int i=0;i<10;i++) team[i]=0;
		cin >> n;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> name[i];
			for(int j=0;j<n-1;j++){
				cin >> r;
				if(r==0)
					team[i] = team[i] + 2;
				else if(r==2)
					team[i] = team[i] + 1;
			}
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(team[i] < team[j]){
					t = team[i];
					team[i] = team[j];
					team[j] = t;
					T = name[i];
					name[i] = name[j];
					name[j] = T;
				}
			}
		}
		for(int i=0;i<n;i++){
			cout << name[i] << endl;
		}
	}
	return 0;
}

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;
}