Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"sort"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw, Index 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
	}
	index := func(c1, c2 *Team) bool {
		return c1.Index < c2.Index
	}

	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, i}
		}
		OrderedBy(win, lose, index).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,ii,jj,n,rr[10][3],r,temp,flg;
	char t[11],ctm,tcopy[11];
	while(1){
		cin>>n;
		if(n==0)break;
		for(i=0;i<n;i++){
			cin>>t[i];
			tcopy[i]=t[i];
			rr[i][0]=0; rr[i][1]=0; rr[i][2]=0;
			for(j=0;j<n-1;j++){
				cin>>r;
				rr[i][r]++;
			}
		}
//		for(i=0;i<n;i++)printf("%c ??????%d?????????%d\n",t[i],rr[i][0],rr[i][1]);
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][0]<rr[j][0]){
					temp=rr[i][0];
					rr[i][0]=rr[j][0];
					rr[j][0]=temp;
					
					temp=rr[i][1];
					rr[i][1]=rr[j][1];
					rr[j][1]=temp;
					
					ctm=t[i];
					t[i]=t[j];
					t[j]=ctm;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][1]>rr[j][1]&&rr[i][0]==rr[j][0]){
					temp=rr[i][0];
					rr[i][0]=rr[j][0];
					rr[j][0]=temp;
					
					temp=rr[i][1];
					rr[i][1]=rr[j][1];
					rr[j][1]=temp;
					
					ctm=t[i];
					t[i]=t[j];
					t[j]=ctm;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][1]==rr[j][1]&&rr[i][0]==rr[j][0]){
					flg=0;
					for(k=0;k<n;k++){
						if(t[i]==tcopy[k])flg=1;
						if(t[j]==tcopy[k]&&flg==0){
							temp=rr[i][0];
							rr[i][0]=rr[j][0];
							rr[j][0]=temp;
							
							temp=rr[i][1];
							rr[i][1]=rr[j][1];
							rr[j][1]=temp;
							
							ctm=t[i];
							t[i]=t[j];
							t[j]=ctm;
							break;
						}
					}
				}
			}
		}
		for(i=0;i<n;i++) cout<<t[i]<<endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

typedef pair<P,Ps> PIS;
PIS team[10];

int main(){
	int n;
	while(cin >> n && n){
		rep(i, n){
			cin >> team[i].second.second;
			team[i].second.first = i;
			team[i].first = P(n-1, 0);
			rep(j, n - 1) {
				int num;
				cin >> num;
				if(num == 0) team[i].first.first--;
				if(num == 1) team[i].first.second++;
			}
		}
		sort(team, team + n);
		rep(i, n) cout << team[i].second.second << endl;
	}
	return 0;
}

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

typedef struct {
	char t;
	int pt[10];
	int win;
	int lose;
} GAME;

int main()
{
	GAME game[10];
	int n;

	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			game[i].win = game[i].lose = 0;
			cin >> game[i].t;
			for (int j = 0; j < n - 1; j++){
				cin >> game[i].pt[j];
				if (game[i].pt[j] == 0){
					game[i].win++;
				}
				else if (game[i].pt[j] == 1){
					game[i].lose++;
				}
			}
		}

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (game[j].win > game[j - 1].win){
					swap(game[j], game[j - 1]);
				}
				else if (game[j].win == game[j - 1].win && game[j].lose < game[j - 1].lose){
					swap(game[j], game[j - 1]);
				}
			}
		}

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

	return (0);
}

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<pair<int,int>, pair<int,string> > > v;
		for(int i = 0; i < n; i++) {
			string s;
			int win = 0;
			int lose = 0;
			cin >> s;
			for(int j = 0; j < n - 1; j++) {
				int t;
				cin >> t;
				if(t == 0)
					win--;
				else if(t == 1)
					lose++;
			}
			v.push_back(pair<pair<int,int>,pair<int,string> >(pair<int,int>(win, lose), pair<int,string>(i,s)));
		}
		sort(v.begin(), v.end());
		for(int i = 0; i < v.size(); i++) {
			cout << v[i].second.second << endl;
		}
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,char> P;
typedef pair<int,P> PP;

bool compare(PP a,PP b){
  return a.first > b.first;
}

int main(){
  int n,res[10];
  char ch;

  while(cin >> n ,n){
    vector<PP> v;
    for(int i = 0 ; i < n ; i++){
      int sum = 0 , f = 0;
      cin >> ch;
      for(int j = 0 ; j < n-1 ; j++){
	cin >> res[j];
	if(res[j]==0) sum += 5;
	else if(res[j]==2) sum++;
	else f++;
      }  
      v.push_back(PP(sum,P(f,ch))); 
    }
    sort(v.begin(),v.end(),compare);
    for(int i = 0 ; i < n ; i++) cout << v[i].second.second << endl;
  }

  return 0;
}

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

using namespace std;

struct team {
	char name;
	int w;
	int l;
	int d;
};

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		team t[10];
		int a;
		for (int i = 0; i < n; i++) {
			cin >> t[i].name;
			t[i].w = t[i].l = t[i].d = 0;
			for (int j = 0; j < n-1; j++) {
				cin >> a;
				if (a == 0) {
					t[i].w++;
				} else if (a == 1) {
					t[i].l++;
				} else {
					t[i].d++;
				}
			}
		}
		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (t[j].w < t[j+1].w) {
					swap(t[j], t[j+1]);
				} else if (t[j].w == t[j+1].w) {
					if (t[j].l > t[j+1].l) {
						swap(t[j], t[j+1]);
					}
				}
			}
		}
		for (int i = 0; i < n; i++) {
			cout << t[i].name << endl;
		}
	}
	return 0;
}