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<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    pair<pii,string> p[10];
    rep(i,n){
      int r;
      cin>>p[i].second;
      rep(j,n-1){
        cin>>r;
        if(r==0)
          p[i].first.first--;
        else if(r==1)
          p[i].first.second++;
      }
    }
    sort(p,p+n);
    rep(i,n)
      cout<<p[i].second<<endl;
  }
}

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

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		double r, w, f;
		priority_queue<pair<double,char>> results;
		for (int i = 0; i < n;++i) {
			cin >> name;
			w = 0.0, f = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				cin >> r;
				if (r == 0)w++;
				if (r == 1)f++;
			}
			f /= 100.0;
			double result = w - f;
			results.push(make_pair(result,name));
		}
		for (int i = 0; i < n; ++i) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pi;

int main(){
  int n;
  while(cin >> n , n){
    Pi match[10];
    string team[10];
    for(int i=0;i<n;i++){
      cin >> team[i];
      match[i].first.first = 0; match[i].first.second = 0;
      match[i].second = i;
      for(int j=0;j<n-1;j++){
	int a; cin >> a;
	if(a == 0) match[i].first.first--;
	else if(a == 1) match[i].first.second++;
    }
    }
    sort(match,match+n);
    for(int i=0;i<n;i++){
      cout << team[match[i].second] << endl;
    }
  }
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<string>s(n);
	vector<int>p(n);
	vector<int>m(n);
	rep(i,n){
	  cin>>s[i];
	  int tmp;
	  rep(j,n-1){
	    cin>>tmp;
		if(!tmp)p[i]++;
		else if(tmp==1)m[i]++;
	  }
	}
	rep(i,n){
	  rep(j,n-i-1){
	    if(p[j]<p[j+1]||(p[j]==p[j+1]&&m[j]>m[j+1])){
		  swap(s[j],s[j+1]);
		  swap(m[j],m[j+1]);
		  swap(p[j],p[j+1]);
		}
	  }
	}
	rep(i,n)cout<<s[i]<<endl;
  }
}

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

typedef struct{
    int win,lose;
}Score_t;


bool comp(const pair<Score_t,char>& x, const pair<Score_t,char>& y){
    if(x.first.win == y.first.win)return x.first.lose < y.first.lose;
    return x.first.win > y.first.win;
}


int main(){
        
    int n;
    vector<pair<Score_t,char> > score;
    
    while(cin>>n, n!=0){
        score.clear();
        
        
        for(int i=0; i<n; i++){
            char id; cin >> id;
            Score_t tmp={0,0};
            for(int j=0; j<n-1; j++){
                int in;
                cin >>in;
                if(in==0)tmp.win++;
                else if(in==1)tmp.lose++;
            }
        
            score.push_back(make_pair(tmp,id));
        }
        
        sort(score.begin(),score.end(),comp);
        for(int i=0; i<n; i++)cout << score[i].second << endl;
    }
    return 0;
}

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

using namespace std;

typedef pair<int, char> P;
typedef pair<int, P> P2;

int main(){
  int n;
  P2 team[11];
  while(cin >> n, n){
    for(int i = 0 ; i < n ; i++){
      team[i].first = 0;
      team[i].second.first = 0;
    }
    
    int op;
    for(int i = 0 ; i < n ; i++){
      cin >>team[i].second.second;
      for(int j = 0 ; j < n-1 ; j++){
	cin >> op;
	if(op == 0) team[i].first++;
	if(op == 1) team[i].second.first++;
      }
    }
    
    for(int i = 0 ; i < n ; i++){
      team[i].second.first *= -1;
    }
    
    stable_sort(team, team+n);
    reverse(team, team+n);
    
    for(int i = 0 ; i < n ; i++){
      cout << team[i].second.second << endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

struct Score {
    int win;
    int lose;
    char id;
    Score(char id, int win, int lose) : id(id), win(win), lose(lose) {}
};
bool operator<(const Score& a, const Score& b){
    return a.win == b.win ? a.lose < b.lose : a.win > b.win;
}

int main()
{
    int n;
    while (n = in()){
        vector<Score> scores;
        rep(i, n){
            char id[8];
            int bucket[3] = {};
            scanf("%s", id);
            rep(j, n - 1) bucket[in()]++;
            scores.push_back(Score(id[0], bucket[0], bucket[1]));
        }
        sort(scores.begin(), scores.end());
        eachv(scores, i) printf("%c\n", scores[i].id);
    }
    return (0);
}