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<iostream>
#include<algorithm>
using namespace std;
int n,r;pair<int,char>d[10];
int main(){
	  while (true) {
       cin>>n;
        if (n == 0)break;
        for (int i = 0; i < n; i++) {
            cin >> d[i].second; d[i].first = i;
            for (int j = 0; j < n - 1; j++) {
                scanf("%d", &r);
                if (r == 0) d[i].first -= 100;
                if (r == 1) d[i].first += 10;
            }
        }
        sort(d, d + n);
        for (int i = 0; i < n; i++) cout<<d[i].second<<endl;
    }

	return 0;
}

C++: #include<iostream>
#include<utility>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<pair<pair<double, double>,char>> results;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		double win, lose,result;
		for (int i = 0; i < n;++i) {
			cin >> name;
			win = 0.0, lose = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				int r;
				cin >> r;
				if (r == 2)continue;
				else if (r == 0)win++;
				else lose++;
			}
			results.emplace(make_pair(make_pair(win,-lose),name));
		}
		while(!results.empty()) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	int n;
	while(cin>>n,n){
		vector<pair<int,char> > data[11];
		rep(i,n){
			int w=0,l=0;
			char t;
			cin>>t;
			rep(j,n-1){
				int a;
				cin>>a;
				if(a==0)w++;
				else if(a==1)l++;
			}
			data[w].push_back(make_pair(l,t));
		}
		for(int i=n-1;i>=0;i--){
			if(data[i].size()>0){
				sort(data[i].begin(),data[i].end());
				for(int j=0;j<data[i].size();j++){
					cout<<data[i][j].second<<endl;
				}
			}
		}
	}
}

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

int main(){
	int team,ttt;
	while(cin>>team,team){
		int win[10]={},lose[10]={};
		char name[10],rank[10];
		for(int i=0;i<team;i++){
			cin>>name[i];
			for(int j=0;j<team-1;j++){
				cin>>ttt;
				if(ttt==0)win[i]++;
				if(ttt==1)lose[i]++;
			}
		}
		for(int i=team-1;i>-1;i--){
			for(int j=0;j<team-i;j++){
				for(int k=0;k<team;k++){
					if(win[k]==i&&lose[k]==j)cout<<name[k]<<endl;
				}
			}
		}
	}
}

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;

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) ));
	}
	sort(RALL(ans));
	REP(i,n) cout << ans[i].second.second << endl;
    }
    return 0;
}

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

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		float r, w, f;
		priority_queue<pair<float,char>> results;
		for (int i = 0; i < n;++i) {
			cin >> name;
			w = 0.0, f = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				cin >> r;
				if (r == 0)w++;
				if (r == 1)f++;
			}
			f /= 1000.0;
			float result = w - f;
			results.push(make_pair(result,name));
		}
		for (int i = 0; i < n; ++i) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class T{
  public:
    char c;
    int a, b, n;
    T(){ a = 0; b = 0; }
    bool operator < (const T &t) const {
      if(a != t.a) return a > t.a;
      if(b != t.b) return b < t.b;
      return n < t.n;
    }
};

int main() {
  int N;
  while(cin >>N && N){
    vector<T> ts(N);
    REP(i, N){
      char c; cin >>c; ts[i].c = c; ts[i].n = i;
      REP(j, N - 1){
        int n; cin >>n;
        if(n == 0) ++ts[i].a;
        if(n == 1) ++ts[i].b;
      }
    }
    SORT(ts);
    REP(i, N) cout <<ts[i].c <<endl;
  }

  
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
pair<int, char>a[100000];
int n, sum, p;
int main() {
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a[i].second;
			sum = 0;
			for (int j = 0; j < n - 1; j++) {
				cin >> p;
				if (p == 0) { sum += 10000; }
				if (p == 2) { sum += 1; }
			}
			a[i].first = sum;
		}
		sort(a, a + n);
		for (int i = n - 1; i >= 0; i++) {
			cout << a[i].second << endl;
		}
	}
}

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

char teamname[10];
int team[10];

void init()
{
	for(int i=0;i<10;i++){
		teamname[i] = NULL;
		team[i] = 0;
	}
}
int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		init();
		int match;
		for(int i=0;i<n;i++){
			cin >> teamname[i];
			for(int j=0;j<n-1;j++){
				cin >> match;
				switch(match){
					case 0:
						team[i]+=10;
						break;
					case 1:
						team[i]-=1;
						break;
					default:
						break;
				}
			}
		}
		for(int j=0;j<n-1;j++){
			for(int i=0;i<n-1-j;i++){
				if(team[i] < team[i+1]){
					int tmp=team[i+1];char tempp = teamname[i+1];
					team[i+1] = team[i];teamname[i+1] = teamname[i];
					team[i] = tmp;teamname[i] = tempp;
				}
			}
		}
		for(int i=0;i<n;i++){
			cout << teamname[i]<< endl;
		}
	}
	return 0;
}