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

}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int n,r;pair<int,char>d[10];
int main(){
	  while (true) {
       cin>>n;
        if (n == 0)break;
        for (int i = 0; i < n; i++) {
            cin >> d[i].second; d[i].first = i;
            for (int j = 0; j < n - 1; j++) {
                scanf("%d", &r);
                if (r == 0) d[i].first -= 100;
                if (r == 1) d[i].first += 10;
            }
        }
        sort(d, d + n);
        for (int i = 0; i < n; i++) cout<<d[i].second<<endl;
    }

	return 0;
}

C++: #include<iostream>
#include<utility>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<pair<pair<double, double>,char>> results;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		double win, lose,result;
		for (int i = 0; i < n;++i) {
			cin >> name;
			win = 0.0, lose = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				int r;
				cin >> r;
				if (r == 2)continue;
				else if (r == 0)win++;
				else lose++;
			}
			results.emplace(make_pair(make_pair(win,-lose),name));
		}
		while(!results.empty()) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	int n;
	while(cin>>n,n){
		vector<pair<int,char> > data[11];
		rep(i,n){
			int w=0,l=0;
			char t;
			cin>>t;
			rep(j,n-1){
				int a;
				cin>>a;
				if(a==0)w++;
				else if(a==1)l++;
			}
			data[w].push_back(make_pair(l,t));
		}
		for(int i=n-1;i>=0;i--){
			if(data[i].size()>0){
				sort(data[i].begin(),data[i].end());
				for(int j=0;j<data[i].size();j++){
					cout<<data[i][j].second<<endl;
				}
			}
		}
	}
}

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

int main(){
	int team,ttt;
	while(cin>>team,team){
		int win[10]={},lose[10]={};
		char name[10],rank[10];
		for(int i=0;i<team;i++){
			cin>>name[i];
			for(int j=0;j<team-1;j++){
				cin>>ttt;
				if(ttt==0)win[i]++;
				if(ttt==1)lose[i]++;
			}
		}
		for(int i=team-1;i>-1;i--){
			for(int j=0;j<team-i;j++){
				for(int k=0;k<team;k++){
					if(win[k]==i&&lose[k]==j)cout<<name[k]<<endl;
				}
			}
		}
	}
}