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<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	char name[10];
	int toku[9][5],n,make,hiki,sum[9],touroku[9];
	int flg[9];
	while(1) {
		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>>toku[i][j];
			}
		}
		for(int i=0;i<n;i++) {sum[i]=0;touroku[i]=0;}
		for(int i=0;i<n;i++) {
			kati=0;make=0;
			for(int j=0;j<n-1;j++) {
				if(toku[i][j]==0) kati++;
				if(toku[i][j]==1) make++;
			}
			sum[i]=kati+(make*-1);
		}
		for(int i=0;i<n;i++) touroku[i]=sum[i];
		sort(sum,sum+n,greater<int>());
		for(int i=0;i<n;i++) flg[i]=0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(sum[i]==touroku[j] && flg[j]==0) {
					cout<<name[j]<<endl;
					flg[j]=1;
					break;
				}
			}
		}
	}
}

C++: #include<stdio.h>
int main(void)
{
    int n,i,j,h,w[10],l[10],t,u[10];
    char q[11],g;
    while(1){
        for(i=0;i<10;i++){
            w[i]=0; l[i]=0;
        }   
        scanf("%d",&n);
        if(n==0) break;
            for(i=0;i<n;i++){
                scanf(" %c",&q[i]);
                for(j=0;j<n-1;j++){
                    scanf("%d",&h);
                    if(h==0) w[i]++;
                    if(h==1) l[i]++;
                }
            }
            for(i=0;i<n-1;i++){
                for(j=i+1;j<n;j++){
                    if(w[i]<w[j]||(w[i]==w[j]&&l[i]>l[j])||(w[i]==w[j]&&l[i]==l[j]&&i>j)){
                        t=w[i];
                        w[i]=w[j];
                        w[j]=t;
                         
                        t=l[i];
                        l[i]=l[j];
                        l[j]=t;
                         
                        t=u[i];
                        u[i]=u[j];
                        u[j]=t;
                     
                        g=q[i];
                        q[i]=q[j];
                        q[j]=g;
                    }               
                }   
            }       
            for(i=0;i<n;i++) printf("%c\n",q[i]);
    }
    return 0;
}

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

int main() {
  int n;
  
  while(cin >> n, n) {
    vector<vector<int> > G(n, vector<int>(n-1, 0));
    vector<int> win(n), lose(n);
    vector<pair<int, string> > team(n);
    
    for(int i=0; i<n; i++) {
      team[i].first = i;
      cin >> team[i].second;
      for(int j=0; j<n-1; j++) {
	cin >> G[i][j];
	win[i]  += G[i][j] == 0;
	lose[i] += G[i][j] == 1;
      }
    }
    
    for(int i=0; i<n-1; i++) {
      for(int j=i+1; j<n; j++) {
	if(win[i] == win[j]) {
	  if(lose[i] == lose[j]
	     && team[i].first > team[j].first) {
	    swap(win[i], win[j]);
	    swap(lose[i], lose[j]);
	    swap(team[i], team[j]);
	  }
	  else if(lose[i] > lose[j]) {
	    swap(win[i], win[j]);
	    swap(lose[i], lose[j]);
	    swap(team[i], team[j]);
	  }
	} else if(win[i] < win[j]){
	  swap(win[i], win[j]);
	  swap(lose[i], lose[j]);
	  swap(team[i], team[j]);
	}
      }
    }
    for(int i=0; i<n; i++) cout << team[i].second << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
struct base{
	char team;
	int win;
	int lose;
};

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		struct base champ[10];
		for(int i=0;i<n;i++){
			champ[i].win = 0;
			champ[i].lose = 0;
		}
		for(int i=0;i<n;i++){
			cin>>champ[i].team;
			for(int j=0;j<n-1;j++){
				int a;
				cin>>a;
				if(a==0) champ[i].win++;
				else if(a==1) champ[i].lose++;
			}
		}
		struct base temp;
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(champ[i].win < champ[j].win){
					temp = champ[i];
					champ[i] = champ[j];
					champ[j] = temp;
				}else if(champ[i].win == champ[j].win){
					if(champ[i].lose > champ[j].lose){
						temp = champ[i];
						champ[i] = champ[j];
						champ[j] = temp;
					}
				}
			}
		}

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

	return 0;
}

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

struct data{
    char name;
    int win, lose;
    data(char n, int w, int l) : name(n), win(w), lose(l) {}
    bool operator<(const data other) const{
        if(win != other.win)    return win < other.win;
        else                    return lose > other.lose;
    }
};

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

        if(n == 0)  break;

        vector<data> result;
        char t;
        int r;

        for(int i = 0; i < n; i++){
            cin >> t;
            int w = 0, l = 0;
            for(int j = 0; j < n-1; j++){
                cin >> r;
                if(r == 0)  w++;
                if(r == 1)  l++;
            }
            result.push_back(data(t, w, l));
        }

        sort(result.rbegin(), result.rend());

        for(data d : result)    cout << d.name << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <sstream>
#include<vector>
using namespace std;


int main(void){
	multimap<int,char,greater<int> > team;
	char t;
	int n;

	while(1)
	{
		cin>>n;
		if(!n) break;
		
		for(int j=0; j<n; j++)
		{
			cin>>t;
			int point=0,r;
			
			for(int i=0; i<n-1; i++)
			{
				cin>>r;
				if(r==0) point+=100;
				else if(r==1) --point;
			}
			team.insert( make_pair( point,t) );
		}

		for(multimap<int,char,greater<int> >::iterator it=team.begin(); it != team.end(); ++it)
			cout<<(*it).second<<endl;
		team.clear();
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j,r,rr[10][3];
string s,t[10];
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)rr[i][0]=rr[i][1]=rr[i][2]=0;
for(i=0;i<n;i++){
cin>>t[i];
for(j=0;j<n-1;j++){cin>>r;rr[i][r]++;}
}
for(i=0;i<n-1;i++){
for(j=n-1;j>i;j--){
if(rr[j-1][0]<rr[j][0]||rr[j-1][0]==rr[j][0]&&rr[j-1][1]>rr[j][1]){
s=t[j-1];t[j-1]=t[j];t[j]=s;
r=rr[j-1][0];rr[j-1][0]=rr[j][0];rr[j][0]=r;
r=rr[j-1][1];rr[j-1][1]=rr[j][1];rr[j][1]=r;
r=rr[j-1][2];rr[j-1][2]=rr[j][2];rr[j][2]=r;
}
}
}
for(i=0;i<n;i++)cout<<t[i]<<endl;
}
return 0;
}