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++: // 2011/02/06 Tazoe

#include <iostream>
using namespace std;

struct team{
	char t;
	int win;
	int los;
	int drw;
	int ord;
};

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

		struct team tea[10];
		for(int i=0; i<n; i++){
			tea[i].win = 0;
			tea[i].los = 0;
			tea[i].drw = 0;
			tea[i].ord = i;

			cin >> tea[i].t;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;
				if(r==0)
					tea[i].win++;
				else if(r==1)
					tea[i].los++;
				else if(r==2)
					tea[i].drw++;
			}
		}

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(tea[i].win<tea[j].win||(tea[i].win==tea[j].win&&tea[i].los>tea[j].los)
				 ||(tea[i].win==tea[j].win&&tea[i].los==tea[j].los&&tea[i].ord>tea[j].ord)){
					struct team tmp = tea[i];
					tea[i] = tea[j];
					tea[j] = tmp;
				}

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

	return 0;
}

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<stdio.h>
int main(void)
{
    int n,i,j,a[10][9],b[10],w,flg[10];
	char name[10],x;
	while(1){
	    scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
		    scanf(" %c",&name[i]);
			for(j=0;j<n-1;j++){
			    scanf(" %d",&a[i][j]);
			}
		}
		for(i=0;i<n;i++) b[i]=0,flg=i;
		for(i=0;i<n;i++){
		    for(j=0;j<n-1;j++){
			    if(a[i][j]==0) b[i]=b[i]+10;
				else if(a[i][j]==2) b[i]=b[i]+1;
			}
		}	
		for(i=0;i<n-1;i++){
		    for(j=i+1;j<n;j++){
			    if(b[i]<b[j]){
				    w=b[i];
					b[i]=b[j];
					b[j]=w;
					x=name[i];
					name[i]=name[j];
					name[j]=x;
					w=flg[i];
					flg[i]=flg[j];
					flg[j]=w;
				}
			}
		}
		for(i=0;i<n-1;i++){
		    if(b[i]==b[i+1]&&flg[i]>flg[i+1]){
			    	w=b[i];
					b[i]=b[i+1];
					b[i+1]=w;
					x=name[i];
					name[i]=name[i+1];
					name[i+1]=x;
					w=flg[i];
					flg[i]=flg[i+1];
					flg[i+1]=w;
		}
		for(i=0;i<n;i++) printf("%c\n",name[i]);
	}
	return 0;
}

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;
long long int i,j,k,n,sum[9],data,a,b;
int main(void)
{
	char name[10];
	while(1) {
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) sum[i]=0;
		
		for(i=0;i<n;i++) {
			cin>>name[i];
			a=b=0;
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) a++;
				else if(data==1) b++;
			}
			sum[i]=a*100000000+b*-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<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;
typedef pair<int,int> Pii;
typedef pair<int,string> Pis;
typedef pair<Pii,Pis> P;
int n,m;P t[10];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i].second.second;
      t[i].second.first=i;
      t[i].first.first=t[i].first.second=0;
      for(int j=0;j<n-1;j++){
	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.second<<endl; 
  }
}

C++: #include<stdio.h>
int main(void)
{
    int n,i,j,h,w[10],l[10],t,u[10];
    char q[11],g;
    while(1){
        for(i=0;i<10;i++){
            w[i]=0; l[i]=0;
        }   
        scanf("%d",&n);
        if(n==0) break;
            for(i=0;i<n;i++){
				u[i]=i;
                scanf(" %c",&q[i]);
                for(j=0;j<n-1;j++){
                    scanf("%d",&h);
                    if(h==0) w[i]++;
                    if(h==1) l[i]++;
                }
            }
            for(i=0;i<n-1;i++){
                for(j=i+1;j<n;j++){
                    if(w[i]<w[j]||(w[i]==w[j]&&l[i]>l[j])||(w[i]==w[j]&&l[i]==l[j]&&u[i]>u[j])){
                        t=w[i];
                        w[i]=w[j];
                        w[j]=t;
                         
                        t=l[i];
                        l[i]=l[j];
                        l[j]=t;
                         
                        t=u[i];
                        u[i]=u[j];
                        u[j]=t;
                     
                        g=q[i];
                        q[i]=q[j];
                        q[j]=g;
                    }               
                }   
            }       
            for(i=0;i<n;i++) printf("%c\n",q[i]);
    }
    return 0;
}