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<bits/stdc++.h>
using namespace std;
long long int sum[11];
int main(void)
{
	int i,j,k,n;
	int data;
	string name[11];
	while(1) {
		cin>>n;
		if(!n) break;
		for(i=0;i<n;i++) sum[i]=0;
		for(i=0;i<n;i++) {
			cin>>name[i];
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) sum[i]+=100;
				else if(data==1) sum[i]--;
				else sum[i]+=15;
			}
		}
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				if(sum[i]<sum[j]) {
					swap(sum[i],sum[j]);
					swap(name[i],name[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<name[i]<<endl;
	}
	return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pair<pii,int>> v(n,mkp(pii(0,0),0));
		vector<char> w(n);
		rep(i,n){
			cin>>w[i];
			string s;
			getline(cin,s);
			stringstream ss;
			ss<<s;
			int t;
			v[i].S=i;
			while(ss>>t){
				if(t==0){
					v[i].F.F--;
				}
				else if(t==2){
					v[i].F.S--;
				}
			}
		}
		sort(ALL(v));
		rep(i,n){
			cout<<w[v[i].S]<<endl;
		}
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

using namespace std;

class team{
public:
	char name;
	int w;
	int l;
	
	bool operator <(const team arg) const{
		if(w == arg.w){
			return l < arg.l;
		}
		return w > arg.w;
	}
};

int main(void){
	int n;
	while(cin >> n && n){
		team t;
		vector<team> v;
		char c;
		int tmp;
		
		for(int j=0;j<n;j++){
			cin >> c;
			t.name = c;
			t.w = 0;
			t.l = 0;
			
			for(int i=0;i<n-1;i++){
				cin >> tmp;
				if(tmp == 0) t.w++;
				if(tmp == 1) t.l++;
			}
			v.push_back(t);
		}
		sort(v.begin(),v.end());
		
		for(int i=0;i<n;i++) cout << v[i].name << endl;
	}
}

C++: #include<stdio.h>
int main(void)
{
    int n, i, t, r, j, temp;
    char str[11] = { 0 };
    char a[10] = { 0 };
    int b[10 + 1][10 + 1];
    int c[10 + 1];
    int d[10 + 1];
    int hideo[10 + 1];
    scanf("%d", &n);
    while (n > 2 && n<10) {
        i = t = r = j = temp = 0;
        for (i = 1; i <= n; i++) {
            c[i] = 0;
            d[i] = 0;
            hideo[i] = 0;
            for (j = 1; j <= n; j++) {
                b[i][j] = 0;
            }
        }

        for (i = 1; i <= n; i++) {
            scanf("%s", &a[i]);
            str[i] = a[i];
            for (j = 1; j <= n - 1; j++) {
                scanf("%d", &b[i][j]);
                if (b[i][j] == 0) {
                    c[i]++;

                }
                if (b[i][j] == 1) {
                    d[i]++;
                }
            }
        }
        for (i = 1; i <= n; i++) {
            hideo[i] = c[i];
        }
        for (i = 1; i < n; i++) {
            for (j = n; j > i; j--) {
                if (c[j] > c[j - 1]) {
                    temp = c[j];
                    c[j] = c[j - 1];
                    c[j - 1] = temp;
                    a[1] = str[j];
                    str[j] = str[j - 1];
                    str[j - 1] = a[1];



                }
            }
        }
        for (i = 1; i <= n; i++) {
            if (c[i] == c[i + 1]) {
                if (d[i] > d[i + 1]) {
                    temp = c[i];
                    c[i] = c[i + 1];
                    c[i + 1] = temp;
                }
            }
        }
        for (i = 1; i <= n; i++) {
            printf("%c\n", str[i]);
        }
        scanf("%d", &n);
    }
}