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
	}

	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++: #include<stdio.h>
int main(void)
{
    int n,r[30],i,j,w,m[30],l[30],a[11];
    char t[11],k;
    while(scanf("%d",&n),n!=0){
        for(i=0;i<n;i++){
            m[i]=0;
            l[i]=0;
            scanf(" %c",&t[i]);
            a[i]=i;
            for(j=0;j<n-1;j++){
                scanf("%d",&r[j]);
                if(r[j]==0){
                    m[i]++;
                }
                else if(r[j]==1){
                    l[i]++;
                }
            }
        }
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(m[i]<m[j]){
                    w=m[i];
                    m[i]=m[j];
                    m[j]=w;
                    w=l[i];
                    l[i]=l[j];
                    l[j]=w;
                    k=t[i];
                    t[i]=t[j];
                    t[j]=k;
                    w=a[i];
                    a[i]=a[j];
                    a[j]=w;
                }
                else if(m[i]==m[j]){
                    if(l[i]>l[j]){
                        w=m[i];
                        m[i]=m[j];
                        m[j]=w;
                        w=l[i];
                        l[i]=l[j];
                        l[j]=w;
                        k=t[i];
                        t[i]=t[j];
                        t[j]=k;
                        w=a[i];
                        a[i]=a[j];
                        a[j]=w;
                    }
                    else if(l[i]==l[j]&&a[i]>a[j]){
                        w=m[i];
                        m[i]=m[j];
                        m[j]=w;
                        w=l[i];
                        l[i]=l[j];
                        l[j]=w;
                        k=t[i];
                        t[i]=t[j];
                        t[j]=k;
                        w=a[i];
                        a[i]=a[j];
                        a[j]=w;
                    }
                }
            }
        }
        for(i=0;i<n;i++){
            printf("%c\n",t[i]);
        }
    }
    return 0;
}

C++: #include<stdio.h>

#include<iostream>


using namespace std ;


pair< int ,int > p[ 10 ] ;



#define name first
#define lose second



int main()
{
	int n ;

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


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



		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 <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<pair<char,int> > a;
        rep(i,n){
            char t;
            cin>>t;
            
            int s=0;
            rep(j,n-1){
                int tr;
                cin>>tr;
                if(tr==0)s+=100;
                if(tr==1)s-=1;
            }
            a.pb(pii(t,s));
        }
        for(int i=0;i<n;i++){
            for(int j=n-1;j>i;j--){
                if( a[j-1].second < a[j].second )swap(a[j-1],a[j]);
            }
        }
        
        rep(i,n){
            cout<<a[i].first<<endl;
        }
    }

    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
struct Data
{
    char name;
    int win;
    int lose;
    bool operator<(const Data& d)const{
        if(win != d.win){
            return win > d.win;
        }
        else{
            return lose < d.lose;
        }
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        Data d[32];
        rep(i,n){
            char team;
            scanf(" %c",&team);
            int w = 0,l = 0;
            rep(j,n-1){
                int x;
                scanf("%d",&x);
                (x == 0) ? ++w : (x == 1) ? ++l :  l+=0;
            }
            d[i].name = team;
            d[i].win = w;
            d[i].lose  = l;
        }
        sort(d,d+n);
        rep(i,n){
            printf("%c\n",d[i].name);
        }
    }
    return 0;
}

C++: #include <iostream> 
#include <vector> 
#include <algorithm> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)  
	bool cmp(const pair<int,char> &a,const pair<int,char> &b){  
		return a.first > b.first; 
}

int main(void){ 
	int n;   
	while(cin >> n,n){       
		vector< pair<int,char> > data(n);      
		rep(i,n){          
			int sum = 0;     
			cin >> data[i].second;   
			rep(j,n-1){              
				int t;                
				cin >> t;              
				sum += (t==0?10:t==2?1:0);  
			} 
			data[i].first = sum; 
		}   
		stable_sort(data.begin(),data.end(),cmp);  
		rep(i,n){         
			cout << data[i].second << endl;       
		}
	}
	return 0;
}