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<string>
using namespace std;
string a[10];
int ans[10];
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++){
		cin>>a[i];
		int z;
		ans[i]=0;
		for(int j=0;j<n-1;j++){
			cin>>z;
			if(z==0)
				ans[i]+=100;
			if(z==2)
				ans[i]++;
		}
	}
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(ans[j]>ans[j-1]){
				int tmp=ans[j];
				ans[j]=ans[j-1];
				ans[j-1]=tmp;
				string ttmp=a[j];
				a[j]=a[j-1];
				a[j-1]=ttmp;
			}
		}
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<endl;
	}
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int n;
	while (cin >> n, n) {
		vector<pair<int, char> > ans[10]; // ????????°, ??????
		
		REP(i, n) {
			string name;
			cin >> name;
			int win = 0, lose = 0;
			REP(j, n - 1) {
				int in; cin >> in;
				if (in == 0) win++;
				if (in == 1) lose++;
			}
			ans[win].push_back(pii(lose, name[0]));
		}
		
		REP(i, 10) sort(ALL(ans[i]));
		
		for (int i = 9; i >= 0; i--) {
			REP(j, ans[i].size()) printf("%c\n", ans[i][j].se);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		vector<pair<string, int>>v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i].first;
			for (int j = 0; j < n - 1; j++) {
				int num;
				cin >> num;
				if (num == 0) v[i].second += 100;
				if (num == 1) v[i].second -= 1;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (v[j].second > v[j - 1].second) swap(v[j], v[j - 1]);
			}
		}
		for (int i = 0; i < n; i++) {
			cout << v[i].first << endl;
		}
	}
	return 0;
}

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

bool hikaku(const pair<int,string>& A,const pair<int,string>& B){
	return A.first > B.first;
}
int main(){
	int n,k,win,lose,les;
	string s;
	
	while(cin >> n,n){
		vector<pair<int,string> >p; // vector < pair <string, int> >p;
	
		for(int i=0;i<n;i++){
			cin >> s ;// cin >> s;
			les = 0;
			for(int j=0;j<n-1;j++){
				cin >> k;
				if(k==0)
				les+=10;//les++;
				if(k==2)//if(k==1)
				les+=1;
			}
			p.push_back( make_pair(les,s) );
		}
		stable_sort(p.begin(),p.end(),hikaku );
		//stable_sprt(p.begin(),p.end(),greater<pair<string , int> >);
		for(int i=0;i<n;i++)
		cout << p[i].second<<endl;
		
	}
	
	
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
/*
struct Team {
    char t;
    int win, lose;
    bool operator < (const Team& team_) const {
        return win == team_.win ? lose > team_.lose : win < team_.win;
    }
};

Team team[11];
*/
int score[11];
int score2[11];
char team[11];
bool check[11];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(cin >> n && n){
        for(int i = 0; i < n; ++i){
           // cin >> team[i].t;
            cin >> team[i];
            score[i] = 0;

            for(int j = 0; j < n - 1; ++j){
                int a;
                cin >> a;
                /*if(a == 0) ++team[i].win;
                if(a == 1) ++team[i].lose;*/
                if(a == 0) score[i] += 100;;
                if(a == 1) score[i] --;
            }
            score2[i] = score[i];
            check[i] = true;
        }

        sort(score, score + n, greater<int>());
/*
        for(int i = n - 1; i >= 0; --i){
            cout << team[i].t << endl;
        }*/
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                if(score[i] == score2[j] && check[j]){
                    cout << team[j] << endl;
                    check[j] = false;
                    break;
                }
            }
        }
    }

    return 0;
}

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

struct record
{
    char t;
    int w, l;
};

void sort( record* a, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
            if( a[j].w > a[j-1].w )
            {
                record temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
            if( a[j].w == a[j-1].w && a[j].l < a[j-1].l )
            {
                record temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
}

int main()
{
    int n;
    char d;
    record team[10];

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

        
        for( int i = 0; i < n; i++ )
        {
            cin >> d;
            team[i].t = d;

            int a = 0, b = 0;
            for( int j = 0; j < n - 1; j++ )
            {
                cin >> d;
                if( d == '0' )
                    a++;
                else if( d == '1' )
                    b++;
                else if( d == '2' );
                else;
            }
            team[i].w = a;
            team[i].l = b;
        }

        sort( team, n );

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

    return 0;
}