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<stdio.h>
int main(void)
{
    int n,r[30],i,j,w,m[30],l[30],a[11];
    char t[11],k;
    while(scanf("%d",&n),n!=0){
        for(i=0;i<n;i++){
            m[i]=0;
            l[i]=0;
            scanf(" %c",&t[i]);
            a[i]=i;
            for(j=0;j<n-1;j++){
                scanf("%d",&r[j]);
                if(r[j]==0){
                    m[i]++;
                }
                else if(r[j]==1){
                    l[i]++;
                }
            }
        }
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(m[i]<m[j]){
                    w=m[i];
                    m[i]=m[j];
                    m[j]=w;
                    w=l[i];
                    l[i]=l[j];
                    l[j]=w;
                    k=t[i];
                    t[i]=t[j];
                    t[j]=k;
                    w=a[i];
                    a[i]=a[j];
                    a[j]=w;
                }
                else if(m[i]==m[j]){
                    if(l[i]>l[j]){
                        w=m[i];
                        m[i]=m[j];
                        m[j]=w;
                        w=l[i];
                        l[i]=l[j];
                        l[j]=w;
                        k=t[i];
                        t[i]=t[j];
                        t[j]=k;
                        w=a[i];
                        a[i]=a[j];
                        a[j]=w;
                    }
                    else if(l[i]==l[j]&&a[i]>a[j]){
                        w=m[i];
                        m[i]=m[j];
                        m[j]=w;
                        w=l[i];
                        l[i]=l[j];
                        l[j]=w;
                        k=t[i];
                        t[i]=t[j];
                        t[j]=k;
                        w=a[i];
                        a[i]=a[j];
                        a[j]=w;
                    }
                }
            }
        }
        for(i=0;i<n;i++){
            printf("%c\n",t[i]);
        }
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,score;
	int tokuten[10];
	char name[10];
	while(1){
		for(int i=0;i<10;i++)
			tokuten[i] = 0;
		cin >> n;
		if(n == 0)
			break;
		for(int i=0;i<n;i++){
			cin >> name[i];
			for(int j=0;j<n-1;j++){
				cin >> score;
				if(score ==0)
					tokuten[i] += 2;
				else if(score == 2)
					tokuten[i] += 1;
			}
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(tokuten[i] < tokuten[j]){
					int T = tokuten[i];
					tokuten[i] = tokuten[j];
					tokuten[j] = T;
					char TT = name[i];
					name[i] = name[j];
					name[j] = TT;
				}
			}
		}
		for(int i=0;i<n;i++)
			cout << name[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

void ins(vector< pair<int,pair<int,char> > > &a){
    int s = a.size() - 1;
    while(a[s].first < a[s-1].first){
	swap(a[s],a[s-1]);
	s--;
	if(s==0) break;
    }
    if(s ==0) return;
    while(a[s].first == a[s-1].first && a[s].second.first > a[s-1].second.first){
	swap(a[s],a[s-1]);
	s--;
	if(s==0) break;
    }
    return ;
}

int main(){
    while(true){
	int n;
	cin >> n;
	vector< pair<int,pair<int,char> > > ans;
	if(n == 0) break;
	REP(i,n){
	    char t;
	    int temp;
	    int w,l;
	    w =0 ;
	    l = 0;
	    cin >> t;
	    REP(i,n-1) {
		cin >> temp;
		if(temp == 0) w++;
		else if( temp == 1) l++;
	    }
	    ans.PB( pair<int,pair<int,char> >( w , pair<int,char>(l,t) ));
	    ins(ans);
	}
	sort(RALL(ans));
	REP(i,n) cout << ans[i].second.second << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct data{
    char name;
    int win;
    int lose;
};

int main(){
    int n;
    struct data data[15];
    while(cin >> n, n){
        rep(i,n){
            cin >> data[i].name;
            data[i].win = data[i].lose = 0;
            rep(j,n - 1){
                int inp;
                cin >> inp;
                if(inp == 0)
                    data[i].win++;
                else if(inp == 1)
                    data[i].lose++;
            }
        }
        rep(i,n){
            rep(j,n - 1){
                if(data[j].win < data[j + 1].win){
                    struct data g = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = g;
                }
                if(data[j].lose > data[j + 1].lose){
                    struct data g = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = g;
                }
            }
        }
        rep(i,n){
            cout << data[i].name << endl;
        }
    }
}

C++: #include <iostream>
using namespace std;
int main()
{
	
	int n;
	char t;
	int r;
	char x[100];

	while(true){
		cin >> n;
		if(n==0)
			break;
		int win[100],lose[100];
		for(int i=0 ;i<10 ;i++){
				win[i] = 0;
				lose[i] = 0;
		}
		for(int i=0 ;i<n ;i++){
			cin >> t;

			for(int j=1 ;j<n ;j++){
				cin >> r;
				if(r==0){
					win[i]++;
				}
			   if(r==1){
					lose[i]++;
				}

			}
			x[i] = t;
		}
		char y=0,z=0;
		for(int i=0 ;i<n-1 ;i++){
				for(int j=i+1 ;j<n ;j++){
				if(win[i] < win[j]){
					z=win[i];
					win[i]=win[j];
					win[j]=z;
					y=x[i];
					x[i]=x[j];
					x[j]=y;
				}
				else if(win[i] == win[j]){
					if(lose[i] > lose[j]){
						z=win[i];
						win[i]=win[j];
						win[j]=z;
						y=x[i];
						x[i]=x[j];
						x[j]=y;
					}
				}					
			
			}
		}

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