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<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>
#include <vector>
#include <set>
#include <string>

using namespace std;
typedef pair<string, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> Vec;
		set<int> Set;
		for(int i = 0; i < n; ++i)
		{
			string t;
			cin >> t;
			int sum = 0;
			for(int j = 0; j < n - 1; ++j)
			{
				int a;
				cin >> a;
				if(a == 0)
				{
					sum += 10000;
				}
				else if(a == 2)
				{
					sum += 100;
				}
			}
			Vec.push_back(P(t, sum));
			Set.insert(sum);
		}
		set<int>::reverse_iterator rit = Set.rbegin();
		while(rit != Set.rend())
		{
			for(int i = 0; i < n; ++i)
			{
				if(*rit == Vec[i].second)
				{
					cout << Vec[i].first << endl;
				}
			}
			++rit;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

int main(){
  int n;
  while(cin >> n, n!=0){
    vector<pair<int, char>> v;

    for(int i=0; i<n; ++i){
      char tmp;
      cin >> tmp;
      v.push_back(make_pair(0, tmp));
      
      for(int j=0; j<n-1; ++j){
	int scr;
	cin >> scr;
	
	if(scr==0){
	  v[i].first = v[i].first + 10;
	}else if(scr==2){
	  v[i].first = v[i].first + 1;
	}
      }
      
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    
    
    for(auto i: v){
      cout << i.second << endl;
    }
  }
  return 0;
}

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

#define WIN 1 << 10
#define LOSE -1

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector< pair<int, char> > team(n);
        for (int i = 0; i < n; i++) {
            char t; cin >> t;
            int r;
            int point = 0;
            for (int j = 0; j < n-1; j++) {
                cin >> r;
                if (r == 0) point += WIN;
                if (r == 1) point += LOSE;
            }
            team[i].first = point;
            team[i].second = t;
        }
        stable_sort(team.begin(), team.end(), greater<pair<int, int> >());
        for (int i = 0; i < n; i++) {
            cout << team[i].second << endl;
        }
    }
    return 0;
}

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

struct team {
  char name;
  int win, lose;
};

bool cmp(const team& a, const team& b) {
  if (a.win != b.win) return a.win > b.win;
  return a.lose < b.lose;
}

int main() {
  int n;
  while (cin >> n, n) {
    char t;
    int r;
    vector<team> v(n);
    for (int i = 0; i < n; i++) {
      cin >> t;
      v[i].name = t;
      for (int j = 0; j < n - 1; j++) {
        cin >> r;
        if (r == 0) v[i].win++;
        else if (r == 1) v[i].lose++;
      }
    }
    sort(v.begin(), v.end(), cmp);
    for (int i = 0; i < n; i++) {
      cout << v[i].name << "\n";
    }
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	char ti[10000];
	int ho[10000];
	while(1){
		int n,win[10000]={},lose[100000]={},blow[100000]={};
	
		cin >> n;
		if(n == 0) break;
		for(int i=0;i < n;i++){
			cin >> ti[i];
			for(int j=0;j<n-1;j++){
				cin >> ho[j];
				if(ho[j] == 0) win[i]+=1;
				if(ho[j] == 1) lose[i]+=1;
			}
		}for(int i=0;i<n;i++){
			for(int j=0;j+1<n;j++){
				if(win[j] < win[j+1] || (win[j]==win[j+1] && lose[j] > lose[j+1]) ){
					swap(lose[j],lose[j+1]);	
					swap(win[j],win[j+1]);	
					swap(ti[j],ti[j+1]);
				}
			}
		}for(int i=0;i<n;i++){
		 cout << ti[i] << endl;	
		}
	}
}