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 <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REP(j,n) for(int j = 0; j < n; j++)

using namespace std;
typedef pair<int, int> P;
struct team {
    string name;
    int win;
    int lose;
    int number;
    team(string n, int numb) {
        name = n;
        win = 0;
        lose = 0;
        number = numb;
    }
    bool operator<( const team& right ) const {
        if(win > right.win) return 0;
        if(win < right.win) return 1;
        if(lose < right.lose) return 0;
        if(lose > right.lose) return 1;
        if(number < right.number) return 0;
        if(number > right.number) return 1;
        return 0;
    }
};
int main() {
    while(1) {
        int n;
        cin >> n;
        if(n == 0) break;
        vector<team> list;
        REP(i,n) {
            string name;
            cin >> name;
            team ck = team(name,i);
            REP(j,n-1) {
                int tmp;
                cin >> tmp;
                
                if(tmp == 0) {
                    ck.win++;
                }
                else if(tmp == 1) {
                    ck.lose++;
                }
            }
            list.push_back(ck);
        }
        sort(list.begin(),list.end());
        
        REP(i,n) {
            team ck = list.back();
            list.pop_back();
            cout << ck.name << endl;
        }
        
        
        
        
        
    }
}

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

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		float r, w, f;
		priority_queue<pair<float,char>> results;
		for (int i = 0; i < n;++i) {
			cin >> name;
			w = 0.0f, f = 0.0f;
			for (int j = 0; j < n - 1; ++j) {
				cin >> r;
				if (r == 0)w++;
				if (r == 1)f++;
			}
			f /= 1000.0f;
			float result = w - f;
			results.push(make_pair(result,name));
		}
		for (int i = 0; i < n; ++i) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: include<iostream>
#include<cstdlib>
#define MAX 10

using namespace std;

struct datum {
	char name;
	int win;
	int lose;
};

datum data[MAX];

int compare ( const void * a, const void * b ) {
	const datum x = *((datum*)a);
	const datum y = *((datum*)b);

	if ( x.win == y.win )
		return x.lose - y.lose;
	return y.win - x.win;
}

int main () {

	while ( true ) {
		int n;
		cin >> n;
		if ( n == 0 )
			break;
		for ( int i=0; i<n; i++ ) {
			cin >> data[i].name;
			int win, lose;
			win = 0;
			lose = 0;
			int now;
			for ( int j=0; j<n-1; j++ ) {
				cin >> now ;
				if ( now == 0 )
					win++;
				if ( now == 1 )
					lose++;
			}
			data[i].win = win;
			data[i].lose = lose;
		}

		qsort ( data, n, sizeof(datum), compare);

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

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]-=100;
			}
		}
		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]<<sum[i]<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
struct {char s; int w, l;} t[10];
int main()
{
	int n, a, i, j, k;
	while (cin >> n, n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> t[i].s;
			for (j = t[i].w = t[i].l = 0; j < n-1; j++)
			{
				cin >> a;
				if (a == 0)
					t[i].w++;
				if (a == 1)
					t[i].l++;
			}
		}
		for (i = 0; i < n-1; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (t[j].w < t[j+1].w)
					swap(t[j], t[j+1]);
				else if (t[j].w == t[j+1].w && t[j].l > t[j+1].l)
					swap(t[j], t[j+1]);
			}
		}
		for (i = 0; i < n; i++)
			cout << t[i].s << endl;
	}
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct data{
    int w,l,p;
    char name;
    data(int a,int b,int c,char d):w(a),l(b),p(c),name(d){}
    data(){}
    bool operator<(const data &d)const{
        if(w!=d.w)return w<d.w;
        if(l!=d.l)return l>d.l;
        return p>d.p;
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        vector<data>V;
        for(int i=0;i<n;i++){
            char c;
            scanf(" %c",&c);
            int w,l;
            w=l=0;
            for(int j=0;j<n-1;j++){
                int val;
                scanf("%d",&val);
                if(val==2)continue;
                if(!val)w++;
                else l++;
            }
            V.push_back(data(w,l,i,c));
        }
        sort(V.rbegin(),V.rend());
        for(int i=0;i<n;i++){
            printf("%c\n",V[i].name);
        }

    }
    return 0;
}

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;i++) {
			for(j=0;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;
}