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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pair<int,string> > team(10);

int main() {
	int n;
	int score;
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			team[i].first=0;
			cin>>team[i].second;
//cout<<team[i].second<<endl;
			int j;
			for(j=0;j<n-1;j++){
				score=in();
				if(score==0)team[i].first+=100;
				if(score==2)team[i].first++;
//cout<<" "<<score<<endl;
			}
//cout<<team[i].second<<" "<<team[i].first<<endl;
		}
		int a,b;
		for(a=0;a<n;a++){
			for(b=0;b<n-1;b++){
				if(team[b].first<team[b+1].first){
					pair<int,string> buf;
					buf=team[b];
					team[b]=team[b+1];
					team[b+1]=buf;
				}
			}
		}
		for(i=0;i<n;i++){
			cout<<team[i].second<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>

using namespace std;

int main(void){
	int a,b,n;
	char t[20];
	int w[10],l[10];
	while(1){
		memset(t,0,sizeof(t));
		memset(w,0,sizeof(w));
		memset(l,0,sizeof(l));
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> t[a];
			for(b=0;b<n-1;b++){
				int b;
				cin >> b;
				if(b==0)w[a]++;
				if(b==1)l[a]++;
			}
		}
		for(a=0;a<n-1;a++){
			for(b=a+1;b<n;b++){
				if(w[b]>w[a] || w[b]==w[a] && l[b]<l[a])swap(t[a],t[b]),swap(w[a],w[b]),swap(l[a],l[b]);
			}
		}
		for(a=0;a<n;a++){
			cout << t[a] << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

class Team{
public:
	char name;
	int win;
	int lost;
	int number;

	bool operator>( const Team& lhs ) const{
		if( win > lhs.win ){
			return true;
		}else if( win < lhs.win ){
			return false;
		} else if( win == lhs.win ){
			if( lost > lhs.lost ){
				return false;
			} else if( lost < lhs.lost ) {
				return true;
			}
		}
		if( number < lhs.number ){
			return true;
		} else {
			return false;
		}
	}

	bool operator<( const Team& lhs ) const{
		if( win < lhs.win ){
			return true;
		}else if( win > lhs.win ){
			return false;
		} else if( win == lhs.win ){
			if( lost < lhs.lost ){
				return false;
			} else if( lost > lhs.lost ) {
				return true;
			}
		}
		if( number > lhs.number ){
			return true;
		} else {
			return false;
		}
	}
};

int main(void)
{
	Team team[11];
	int n;
	int input_data[11];
	char input_name;

	while( cin >> n && n != 0 ){
		for( int i = 0;i < 11;i++ ){
			team[i].win = team[i].lost = team[i].name = team[i].number = 0;
		}

		for( int i = 0;i < n;i++ ){
			cin >> input_name;
			for( int j = 0;j < n - 1;j++ ){
				cin >> input_data[j];
				if( input_data[j] == 0 ) team[i].win++;
				else if( input_data[j] == 1 ) team[i].lost++;
			}

			team[i].name = input_name;
			team[i].number = i;
			
		}

		stable_sort( team, team + n, greater<Team>() );

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


	}
	
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
pair<int, char>a[100000];
int n, sum, p;
int main() {
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a[i].second;
			sum = 0;
			for (int j = 0; j < n - 1; j++) {
				cin >> p;
				if (p == 0) { sum += 10000; }
				if (p == 2) { sum += 1; }
			}
		}
		sort(a, a + n);
		for (int i = n - 1; i >= 0; i++) {
			cout << a[i].second << endl;
		}
	}
}

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

int main(){
	
	int n , m ;
	
	while( cin >> n , n ){
		int count[52][2] = {} ;
		char t[52] = {} ;
		
		for( int i=0 ; i<n ; i++ ){
			cin >> t[i] ;
			for( int j=0 ; j<n-1 ; j++ ){
				cin >> m ;
				if( m!=2 ) count[i][m]++;
			}
		}
		
		for( int i=0 ; i<n ; i++ ){
			for( int j=i+1 ; j<n ; j++ ){
				if( count[i][0] <= count[j][0] ){
					if( count[i][0] != count[j][0] ){
						swap( count[i] , count[j] ) ;
						swap( t[i] , t[j] ) ;
					}else {
						if( count[i][1] > count[j][1] )
							swap( t[i] , t[j] ) ;
					}
				}
			}
		}
		
		for( int i=0 ; i<n ; i++ ) cout << t[i] << endl ;
	}
	
return 0 ;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

class Team{
  public:
  string name;
  int win;
  int lose;
  bool operator <(const Team& o) const
  {
    if(win > o.win) return true;
    if(win < o.win) return false;
    if(lose < o.lose) return true;
    return false;
  }
};

int main(void){  
  int n;
  while(cin >> n,n){
    vector<Team> t(n);
    REP(i,n){
      t[i].win = 0;
      t[i].lose = 0;
    }
    int bf;
    REP(i,n){
      cin >> t[i].name;
      REP(j,n-1){
        cin >> bf;
        if(bf==0) t[i].win++;
        if(bf==1) t[i].lose++;
      }
    }
    sort(t.begin(),t.end());
    REP(i,n)
      cout << t[i].name << endl;
  }
}