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

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a;
  while(cin >>n &&n){
    string s;
    vector<pair<string,pii>> m(n);
    rep(i,n){
      cin >> s;
      m[i].fi = s;
      rep(j,n-1){
        cin >> a;
        if(a == 0)
          m[i].se.fi++;
        else if(a == 1){
          m[i].se.se++;
        }
      }
    }
    sort(all(m),[](const pair<string,pii> &a,const pair<string,pii> &b){
        if(a.se.fi == b.se.fi) return a.se.se < b.se.se;
        return a.se.fi > b.se.fi;
        });
    for(auto it = m.begin(); it != m.end(); ++it){
      cout << it->fi << endl;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
typedef pair<P, int> Pc;

int main() {
    int N;
    while (cin >> N, N) {
        vector<Pc> pc;
        for (int i = 0; i < N; i++) {
            int a = 0, b = 0, c;
            char s;
            cin >> s;
            c = (N-i) * 1000 + s;
            for (int j = 0; j < N - 1; j++) {
                int t; cin >> t;
                if (t == 0) a++;
                if (t == 2) b++;
            }

            pc.push_back(Pc(P(a, b), c));
        }

        sort(pc.begin(), pc.end());

        for (int i = 0; i < N; i++)
            cout << (char)(pc[N-1-i].second  % 1000)<< endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	while ( 1 )
	{
		int n;
		cin >> n;
		if ( n == 0 )
			break;

		vector <int> id( n );
		vector <char> names( n );
		vector <int> wins( n, 0 );
		vector <int> loses( n, 0 );
		for ( int i = 0; i < n; i++ )
		{
			id[i] = i;
			cin >> names[i];

			for ( int j = 0; j < n - 1; j++ )
			{
				int s;
				cin >> s;
				if ( s == 0 )
					wins[i]++;
				else if ( s == 1 )
					loses[i]++;
			}
		}

		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i+1; j < n; j++ )
			{
				if ( wins[i] < wins[j] )
				{
					swap( id[i], id[j] );
					swap( wins[i], wins[j] );
					swap( loses[i], loses[j] );
					swap( names[i], names[j] );
				}
				else if ( wins[i] == wins[j] )
				{
					if ( loses[i] > loses[j] )
					{
						swap( id[i], id[j] );
						swap( wins[i], wins[j] );
						swap( loses[i], loses[j] );
						swap( names[i], names[j] );
					}
					else if ( loses[i] == loses[j] )
					{
						if ( i < j )
						{
							swap( id[i], id[j] );
							swap( wins[i], wins[j] );
							swap( loses[i], loses[j] );
							swap( names[i], names[j] );
						}
					}
				}
			}
		}

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

	}
	return 0;
}

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

using namespace std;

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

    if(n == 0){
      break;
    }

    vector<pair<int,int>> total_result;
    int result;
    vector<char> team;

    for(int i = 0;i < n;++i){
      int point = 0;
      char name;
      cin>>name;
      team.push_back(name);


      for(int j = 0;j < n - 1;++j){
        cin>>result;
        if(result == 0){
          point -= 100;
        }
        else if(result == 2){
          point -= 1;
        }
      }

      total_result.push_back(make_pair(point,i));
    }

    sort(total_result.begin(),total_result.end());

    for(int i = 0;i < n;++i){
      cout<<team.at(total_result[i].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], tmp;
	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].lose){
					swap(game[j], game[j - 1]);
				}
			}
		}

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

	return (0);
}