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

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

struct Team {

	char name;
	int  winCnt;
	int  loseCnt;

};

int main()
{

	int n, r;
	Team t[10];

	while( cin >> n, n ) {

		for( int i = 0; i < 10; i++ ) { t[i].winCnt = 0; t[i].loseCnt = 0; }

		for( int i = 0; i < n; i++ ) {
			cin >> t[i].name;
			for( int j = 0; j < n - 1; j++ ) {

				cin >> r;
				if( r == 0 ) t[i].winCnt++;
				else if( r == 1 ) t[i].loseCnt++;

			}
		}

		for( int i = 0; i < n - 1; i++ ) {
			for( int j = i + 1; j < n; j++ ) {

				Team temp;

				if( t[i].winCnt == t[j].winCnt ) {
					if( t[i].loseCnt == t[j].loseCnt ) continue;
					if( t[i].loseCnt > t[j].loseCnt ) {

						temp = t[i];
						t[i] = t[j];
						t[j] = temp;

					}
				}
				else if( t[i].winCnt < t[j].winCnt ) {

					temp = t[i];
					t[i] = t[j];
					t[j] = temp;

				}

			}
		}

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

	}

	return 0;

}