Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"sort"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw, Index 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
	}
	index := func(c1, c2 *Team) bool {
		return c1.Index < c2.Index
	}

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

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[11],f[11],g,h,i,j;
	char z[11][11],x[11];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			d[i]=0;
			f[i]=0;
			scanf("%s",z[i]);
			for(j=0;j<a-1;j++){
				scanf("%d",&s);
				if(s==0) d[i]++;
				if(s==1) f[i]++;
			}
		}
	//	for(i=0;i<a;i++) printf("%d %d\n",d[i],f[i]);
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(d[i]<d[j]){
					g=d[i];
					d[i]=d[j];
					d[j]=g;
					g=f[i];
					f[i]=f[j];
					f[j]=g;
					strcpy(x,z[i]);
					strcpy(z[i],z[j]);
					strcpy(z[j],x);
				}
				if(d[i]==d[j]){
				//	printf("aaaaa\n");
					if(f[i]>f[j]){
				//	printf("bbbbb\n");
						g=d[i];
						d[i]=d[j];
						d[j]=g;
						g=f[i];
						f[i]=f[j];
						f[j]=g;
						strcpy(x,z[i]);
						strcpy(z[i],z[j]);
						strcpy(z[j],x);
					}
				}
			}
		}
		for(i=0;i<a;i++){
				printf("%c\n",z[i][0]);
		}
	}
	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=i+1;j<n;j++){
if(rr[i][0]<rr[j][0]||rr[i][0]==rr[j][0]&&rr[i][1]>rr[j][1]){
s=t[i];t[i]=t[j];t[j]=s;
r=rr[i][0];rr[i][0]=rr[j][0];rr[j][0]=r;
r=rr[i][1];rr[i][1]=rr[j][1];rr[j][1]=r;
r=rr[i][2];rr[i][2]=rr[j][2];rr[j][2]=r;
}
}
}
for(i=0;i<n;i++)cout<<t[i]<<endl;
}
return 0;
}

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

typedef pair<char, int> pii;

bool fanc(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			char c;
			int num, sum = 0;
			cin >> c;
			
			for (int j = 1; j < n; j++){
				cin >> num;
				sum += num;
			}
			
			p[i] = make_pair(c, sum);
		}
		
		sort(p.begin(), p.end(), fanc);
		
		for (int i = 0; i < n; i++){
			cout << p[i].first << endl;
		}
	}
	
	return (0);
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,point,win[10],low[10];
    char str[10];
    while(cin>>n&&n!=0){
        for(int i=0;i<n;i++){
            win[i]=0;low[i]=0;
            cin>>str[i];
            for(int j=1;j<n;j++){
                cin>>point;
                if(point==0)win[i]++;
                else if(point==1)low[i]++;
            }
        }
        for(int i=0;i<n;i++){
            point=0;
            for(int j=0;j<n;j++)if(win[point]<=win[j]&&low[point]>low[j])point=j;
            cout<<str[point]<<endl;
            win[point]=-10;
            low[point]=20;
        }
    }

}

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

class team{
public:
	int w,l;
	char name;
	team(){
		w = l = 0;
	}
	void clear(){
		w = l = 0;
	}
}T[10];

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

int main(){
	int n,tmp;
	char ntmp;
	int ans[10];
	while(true){
		cin >> n;
		if(n==0)
			break;
		for(int i=0; i<n; i++){
			ans[i] = i;
			cin >> ntmp;
			T[i].name = ntmp;
			for(int j=0; j<n-1; j++){
				cin >> tmp;
				if(tmp == 0)
					T[i].w++;
				else if(tmp == 1)
					T[i].l++;
			}
		}
		sort(ans, n);
		for(int i=0; i<n; i++){
			cout << T[ans[i]].name << endl;
			T[i].clear();
		}
	}
	return 0;
}

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

struct Team {
  string name;
  int game[3];
  
  bool operator<(const Team &t) const {
    if( game[0] != t.game[0] ) return game[0] > t.game[0];
    if( game[1] != t.game[1] ) return game[1] < t.game[1];
    return false;
  }
};

int main() {
  for( int N; cin >> N, N;  ) {
    
    Team team[N];

    for(int i = 0; i < N; i++) {
      cin >> team[i].name;
      for(int j = 0; j < 3; j++) team[i].game[j] = 0;

      for(int j = 0; j < N - 1; j++) {
        int x; cin >> x;
        team[i].game[x]++;
      }
    }
    
    sort( team, team + N );
    for(int i = 0; i < N; i++) cout << team[i].name << endl;

  }
}

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

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


using namespace std;
struct node{
  char name;
  int win,lost;
  node(char n,int w, int l): name(n),win(w), lost(l){}
  bool operator <(const node &e) const{
    if(win == e.win)
      lost <e.lost;
    else
      return win > e.win;
  }

  bool operator >(const node &e) const{
    if(win == e.win)
      lost >e.lost;
    else
      return win < e.win;
      }
};


int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<node> data;
      for(int i=0;i<n;i++)
	{
	  char t;
	  cin>>t;
	  int win=0;
	  int lost=0;
	  for(int i=1;i<n;i++)
	    {
	      int tmp;
	      cin>>tmp;
	      if(tmp==0)
		win++;
	      else if(tmp==1)
		lost++;
	    }
	  data.push_back(node(t,win,lost));
	}
      sort(data.begin(),data.end());
      for(int i=0;i<n;i++)
	cout<<data[i].name<<endl;
    }
  
}