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, draw).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

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<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>

using namespace std;
long long int sum[9];
int main(void)
{
	char name[10];
	int toku[9][9],n,make,kati,hiki,touroku[9];
	int flg[10];
	while(1) {
		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>>toku[i][j];
			}
		}
		for(int i=0;i<n;i++) {sum[i]=0;touroku[i]=0;}
		for(int i=0;i<n;i++) {
			kati=0;make=0;
			for(int j=0;j<n-1;j++) {
				if(toku[i][j]==0) kati++;
				if(toku[i][j]==1) make++;
			}	
			sum[i]=kati*100000000+(make*-1);
		}
		for(int i=0;i<n;i++) touroku[i]=sum[i];
		sort(sum,sum+n,greater<int>());
		for(int i=0;i<n;i++) flg[i]=0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(sum[i]==touroku[j] && flg[j]==0) {
					cout<<name[j]<<endl;
					flg[j]=1;
					break;
				}
			}
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <sstream>
#include<vector>
using namespace std;


int main(void){
	multimap<int,char,greater<int> > team;
	char t;
	int n;

	while(1)
	{
		cin>>n;
		if(!n) break;
		
		for(int j=0; j<n; j++)
		{
			cin>>t;
			int point=0,r;
			
			for(int i=0; i<n-1; i++)
			{
				cin>>r;
				if(r==0) point+=2;
				else if(r==1) --point;
			}
			team.insert( make_pair( point,t) );
		}

		for(multimap<int,char,greater<int> >::iterator it=team.begin(); it != team.end(); ++it)
			cout<<(*it).second<<endl;
		team.clear();
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int main(){
	int n;
	while( cin >> n , n ){
		// pair<int,P> Í (¿,-¯,-üÍ³ê½Ô)
		// char Í`[¼(At@xbg1¶)
		char c[12] = {0};
		vector<pair<int,P> > v;
		
		for(int i=0 ; i < n ; i++ ){
			char t;
			int win=0, lose=0;
			cin >> t;
			c[i] = t;
			for(int j=0 ; j < n-1 ; j++ ){
				int r;
				cin >> r;
				if( r == 0 ){
					win++;
				}else if( r == 1 ){
					lose++;
				}
			}
			// pair<int,P> Í (¿,-¯,-üÍ³ê½Ô)
			P p( -lose , -i );
			pair<int,P> p_(win,p);
			v.push_back( p_ );
		}
		sort( v.rbegin() , v.rend() );
		for(int i=0 ; i < v.size() ; i++ ){
			cout << c[ -v[i].second.second ] << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

struct Team
{
    int win, lose, num;
    char name;

    Team () {}
    Team ( int win, int lose, char name, int num) : win(win), lose(lose), name(name), num(num) {}

    bool operator < ( const Team &d ) const
    {
        return ( win < d.win || win == d.win && (lose > d.lose || lose == d.lose && num > d.num));    }

    bool operator > ( const Team &d ) const
    {
        return ( !(*this < d) );
    }
};

int main()
{
    int N;
    Team data[15];

    while ( cin >> N, N ) {
        for ( int i = 0; i < N; i++ ) {
            int win = 0, lose = 0;
            char name;
            cin >> name;
            for ( int j = 0; j < N - 1; j++ ) {
                int d;
                cin >> d;
                switch ( d ) {
                    case 0 :
                        win++;
                        break;
                    case 1 :
                        lose++;
                        break;
                }
            }
            data[i] = Team ( win, lose, name, i );
        }
        sort ( data, data + N, greater<>());
        for ( int i = 0; i < N; i++ ) {
            cout << data[i].name << endl;
        }
    }

    return ( 0 );
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long int i,j,k,n,a,b,sum;
	while(1) {
		cin>>n;
		vector<pair<long long int,string> > pp(n);
		if(n==0) break;
		for(i=0;i<n;i++) {
			cin>>pp[i].second;
			sum=0;
			for(j=0;j<n-1;j++) {
				cin>>a;
				if(a==0) sum+=10000000;
				if(a==1) sum-=1;
			}
			pp[i].first=sum;
		}
		stable_sort(pp.begin(),pp.end());
		for(i=n-1;i>=0;i--) {
			cout<<pp[i].second<<endl;
		}
	}
	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*1000000+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;
}