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 <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

#define WIN 1000
#define LOSE -1

struct Bigger {
    bool operator()(pair<int, char>a, pair<int, char>b) {
        return a.first > b.first;
    }
};

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector< pair<int, char> > team(n);
        for (int i = 0; i < n; i++) {
            char t; cin >> t;
            int r;
            int point = 0;
            for (int j = 0; j < n-1; j++) {
                cin >> r;
                if (r == 0) point += WIN;
                if (r == 1) point += LOSE;
            }
            team[i].first = point;
            team[i].second = t;
        }
        stable_sort(team.begin(), team.end(), Bigger());
        for (int i = 0; i < n; i++) {
            cout << team[i].second << endl;
        }
    }
    return 0;
}

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

using namespace std;

typedef pair<string, int[3]> term;

bool srt(term a, term b){
	return  a.second[0] > b.second[0] || (a.second[0] == b.second[0] && a.second[1] < b.second[1]);
}

int main(){
	int n;
	int num;
	while(cin >> n, n){
		term result[10];

		for(int i=0; i < n; i++){
			cin >> result[i].first;

			for(int j=0; j < n-1; j++){
				cin >> num;
				result[i].second[num]++;
			}
		}
		stable_sort(result, result+n, srt);
		for(int i=0; i < n; i++){
			cout << result[i].first << endl;
		}

	}
}

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

int main() {
  int n;
  while(cin >> n, n) {
    char t[n]; 
    int p[n][3];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < 3; j++) {
        p[i][j] = 0;
      }
    }

    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(j == 0) cin >> t[i];
        else {
          int x; cin >> x;
          p[i][x]++;
        }
      }
    }
    
    for(int i = 0; i < n; i++) {
      int wm = -1, lm = 1000, pos;
      for(int j = 0; j < n; j++) {
        if(p[j][0] >= wm) {
          if(p[j][0] == wm && p[j][1] >= lm) continue;
          wm = p[j][0], lm = p[j][1], pos = j;
        }
      }
      printf("%c\n",t[pos]);
      p[pos][0] = -1, p[pos][1] = 1000;
    } 
  }
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		char T[10];
		int W[10], L[10], I[10];

		for(int i=0; i<n; i++){
			cin >> T[i];

			W[i] = L[i] = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;

				if(r==0){
					W[i]++;
				}
				else if(r==1){
					L[i]++;
				}
			}

			I[i] = i;
		}

		for(int i=0; i<n-1; i++){
			for(int j=i+1; j<n; j++){
				if(W[i]<W[j]
				 ||(W[i]==W[j]&&L[i]>L[j])
				 ||(W[i]==W[j]&&L[i]==L[j]&&I[i]>I[j])){
					char c_tmp = T[i];
					T[i] = T[j];
					T[j] = c_tmp;

					int tmp = W[i];
					W[i] = W[j];
					W[j] = tmp;

					tmp = L[i];
					L[i] = L[j];
					L[j] = tmp;

					tmp = I[i];
					I[i] = I[j];
					I[j] = tmp;
				}
			}
		}

		for(int i=0; i<n; i++){
			cout << T[i] << '\n';
		}
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
const int MAX=10;
int main(){
	char team[MAX+1];
	int n,score;
	int sum[MAX+1];
	while(cin >> n){
		if(n==0) break;
		for(int i=0; i<n; i++) sum[i]=0;
		
		for(int k=0; k<n; k++){
			cin >> team[k];
			for(int i=0; i<n-1; i++){
				cin >> score;
				if(score==0) sum[k]+=2;
				if(score==2) sum[k]+=1;
			}
			cout << team[k] << " " << sum[k] << endl;
		}
		int count=0;
		while(count!=n){
			int max_score=sum[0],winer=0;
			for(int i=0; i<n; i++){
				if(max_score < sum[i]){
					max_score = sum[i];
					winer=i;
				}
			}
			cout << team[winer] << endl;
			sum[winer]=-1;
			count++;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
struct base{
	char team;
	int win;
	int lose;
};

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		struct base champ[10]={0};
		for(int i=0;i<n;i++){
			cin>>champ[i].team;
			for(int j=0;j<n-1;j++){
				int a;
				cin>>a;
				if(a==0) champ[i].win++;
				else if(a==1) champ[i].lose++;
			}
		}
		struct base temp;
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(champ[i].win < champ[j].win){
					temp = champ[i];
					champ[i] = champ[j];
					champ[j] = temp;
				}else if(champ[i].win == champ[j].win){
					if(champ[i].lose >champ[j].lose){
						temp = champ[i];
						champ[i] = champ[j];
						champ[j] = temp;
					}
				}
			}
		}

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

	return 0;
}

C++: // 2011/07/31 Tazoe

#include <iostream>
using namespace std;

struct team{
	char nam;
	int  win;
	int  los;
	int  drw;
	int  sn;
};

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		struct team T[10];
		for(int i=0; i<n; i++){
			cin >> T[i].nam;

			T[i].win = T[i].los = T[i].drw = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;
				if(r==0)
					T[i].win++;
				else if(r==1)
					T[i].los++;
				else if(r==2)
					T[i].drw++;
			}

			T[i].sn = i;
		}

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(T[i].win<T[j].win
				 ||(T[i].win==T[j].win&&T[i].los>T[j].los)
				 ||(T[i].win==T[j].win&&T[i].los==T[j].los&&T[i].sn>T[j].sn)){
					struct team tmp = T[i];
					T[i] = T[j];
					T[j] = tmp;
				}

		for(int i=0; i<n; i++)
			cout << T[i].nam << endl;
	}

	return 0;
}