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>
using namespace std;
int main()
{
        while(true){
                int n;
                char t;
                int r;
                char x[10];
                cin >> n;
                if(n==0)
                        break;
                int win[10],lose[10];
                for(int i=0 ;i<10 ;i++){
                                win[i] = 0;
                                lose[i] = 0;
                }
                for(int i=0 ;i<n ;i++){
                        cin >> t;

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

                        }
                        x[i] = t;
                }
                char y=0;
				int z=0;

                for(int i=0 ;i<n-1 ;i++){
                                for(int j=i+1 ;j<n ;j++){
                                if(win[i] < win[j]){
                                        z=win[i];
                                        win[i]=win[j];
                                        win[j]=z;
                                        y=x[i];
                                        x[i]=x[j];
                                        x[j]=y;
                                }
                                else if(win[i] == win[j]){
                                        if(lose[i] > lose[j]){
                                                z=win[i];
                                                win[i]=win[j];
                                                win[j]=z;
                                                y=x[i];
                                                x[i]=x[j];
                                                x[j]=y;
                                        }
                                }
								else if(win[i] == win[j] && lose[i] == lose[j]){
									if(x[i] > x[j]){
										z=win[i];
                                        win[i]=win[j];
                                        win[j]=z;
										y=x[i];
                                        x[i]=x[j];
                                        x[j]=y;
									}
								}
                        }
                }

                for(int i=0 ;i<n ;i++){
                        cout << x[i] << endl;
                }
        }
		return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

void ins(vector< pair<int,pair<int,char> > > &a){
    int s = a.size() - 1;
    if(s == 0) return ;
    while(a[s].first < a[s-1].first){
	swap(a[s],a[s-1]);
	s--;
	if(s==0) break;
    }
    if(s ==0) return;
    while(a[s].first == a[s-1].first && a[s].second.first > a[s-1].second.first){
	swap(a[s],a[s-1]);
	s--;
	if(s==0) break;
    }
    return ;
}

int main(){
    while(true){
	int n;
	cin >> n;
	vector< pair<int,pair<int,char> > > ans;
	if(n == 0) break;
	REP(i,n){
	    char t;
	    int temp;
	    int w,l;
	    w =0 ;
	    l = 0;
	    cin >> t;
	    REP(i,n-1) {
		cin >> temp;
		if(temp == 0) w++;
		else if( temp == 1) l++;
	    }
	    ans.PB( pair<int,pair<int,char> >( w , pair<int,char>(l,t) ));
	    ins(ans);
	}
	sort(RALL(ans));
	REP(i,n) cout << ans[i].second.second << endl;
    }
    return 0;
}

C++: #include<stdio.h>

#include<iostream>


using namespace std ;



#define name first
#define lose second



int main()
{
	int n ;

	while( 1 )
	{
		scanf( "%d" ,&n ) ;


		if( n == 0 )
		{
			return 0 ;
		}



		pair< int, int > p[ 10 ] ;



		int a ;

		char c[ 2 ] ;

		int i ,j ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%s" ,c ) ;


			p[ i ].name = c[ 0 ] * 100 ;


			for( j = 1 ; j < n ; ++j )
			{
				scanf( "%d" ,&a ) ;


				if( a < 2 )
				{
					if( a )
					{
						--p[ i ].lose ;
					}

					else
					{
						++p[ i ].name ;
					}
				}
			}
		}


		for( i = 0 ; i < n ; ++i )
		{
			for( j = i ; j < n ; ++j )
			{
				pair< int ,int > tmp ;

				if( p[ i ].name % 100 < p[ j ].name % 100 )
				{
					tmp = p[ i ] ;

					p[ i ] = p[ j ] ;

					p[ j ] = tmp ;
				}

				else if( p[ i ].lose < p[ j ].lose )
				{
					tmp = p[ i ] ;

					p[ i ] = p[ j ] ;

					p[ j ] = tmp ;
				}
			}
		}


		for( i = 0 ; i < n ; ++i )
		{
			printf( "%c\n" ,p[ i ].name / 100 ) ;
		}
	}
}

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

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,point,win[10],low[10];
    char str[10];
    while(cin>>n&&n!=0){
        for(int i=0;i<n;i++){
            win[i]=0;low[i]=0;
            cin>>str[i];
            for(int j=1;j<n;j++){
                cin>>point;
                if(point==0)win[i]++;
                else if(point==1)low[i]++;
            }
        }
        for(int i=0;i<n;i++){
            point=0;
            for(int j=1;j<n;j++)if(win[point]<win[j]||win[point]==win[j]&&low[point]>low[j])point=j;
            cout<<str[point]<<endl;
            win[point]=-1;
            low[point]=11;
        }
    }

}