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 <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);
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[100];
	int i,j,temp;
	int w[100],l[100],a[100];
	char t[100],m;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			w[i]=0;
			l[i]=0;
			scanf(" %c",&t[i]);
			a[i]=i;
			for(j=0;j<n-1;j++){
				scanf("%d",&p[j]);
				if(p[j]==0){
					w[i]++;
				}
				if(p[j]==1){
					l[i]++;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(w[i]<w[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && l[i]>l[j]){
					temp=l[i];
					l[i]=l[j];
					l[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && l[i]==l[j] && a[i]>a[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%c\n",t[i]);
		}
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int team[n][n-1];
		char name[n];
		rep(i,n){
			cin>>name[i];
			rep(j,n-1){
				cin>>team[i][j];
			}
		}
		int win[n];
		int lose[n];
		rep(i,n){
			win[i]=0;
			lose[i]=0;
		}
		rep(i,n){
			rep(j,n-1){
				if(team[i][j]==0)win[i]++;
				else if(team[i][j]==1)lose[i]++;
			}
		}
		rep(i,n){
			for(int j=n-2;j>=i;j--){
				if(win[j+1]>win[j]){
					int alt=win[j];
					win[j]=win[j+1];
					win[j+1]=alt;
					alt=lose[j];
					lose[j]=lose[j+1];
					lose[j+1]=alt;
					char c=name[j];
					name[j]=name[j+1];
					name[j+1]=c;
				}else if(win[j+1]==win[j]){
					if(lose[j+1]<lose[j]){
						int alt=win[j];
						win[j]=win[j+1];
						win[j+1]=alt;
						alt=lose[j];
						lose[j]=lose[j+1];
						lose[j+1]=alt;
						char c=name[j];
						name[j]=name[j+1];
						name[j+1]=c;
					}
				}
			}
		}
		rep(i,n){
			cout<<name[i]<<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct data{
	string team;
	int win, lose, order;
};

bool cmp(data d1, data d2){
	if(d1.win != d2.win) return d1.win > d2.win;
	if(d1.lose != d2.lose) return d1.lose < d2.lose;
	return d1.order < d2.order;
}

signed main() {
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		vector<data> d(n);
		string s;
		int a, win, lose;
		rep(i, 0, n){
			cin >> s;
			win = 0;
			lose = 0;
			rep(j, 0, n - 1){
				cin >> a;
				if(a == 0) win++;
				else if(a == 1) lose++;
			}
			d[i].team = s;
			d[i].win = win;
			d[i].lose = lose;
			d[i].order = i;
		}
		sort(all(d), cmp);
		rep(i, 0, n){
			cout << d[i].team <<endl;
		}
	}
}