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
	}

	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<iostream>

using namespace std;

struct sct
{
	char t;
	int r1[11];
	int win;
	int lose;
	int drow;
	int input;
};

int main()
{
	while(true)
	{
		int n = 0;
		sct team[11];
		sct cl = {0, 0, 0, 0, 0, 0}; 

		cin >> n;

		if(n == 0)
		{
			return false;
		}

		for(int i= 0; i < n; i++)
		{
			team[i] = cl;
			team[i].input = i;
			
			cin >> team[i].t;

			for(int j = 0; j < n - 1; j++)
			{
				cin >> team[i].r1[j];
			}
		}

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n - 1; j++)
			{
				if(team[i].r1[j] == 0)
				{
					team[i].win++;	
				}
				
				else if(team[i].r1[j] == 1)
				{
					team[i].lose++;
				}
				else if (team[i].r1[j] == 2)
				{
					team[i].drow++;
				}				
			}
		}

		for(int i = 0; i < n; i++)
		{
			for(int j = i; j < n; j++)
			{
				if(team[i].win < team[j].win)
				{
					sct tmp = team[i];
					team[i] = team[j];
					team[j] = tmp;
				}
				else if(team[i].win == team[j].win)
				{
					if(team[i].lose > team[j].lose)
					{
						sct tmp = team[i];
						team[i] = team[j];
						team[j] = tmp;
					}
					else if(team[i].lose == team[j].lose)
					{
						if(team[i].input > team[j].input)
						{
							sct tmp = team[i];
							team[i] = team[j];
							team[j] = tmp;
						} 	
					}
				}
			}
		}

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

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=5+3*1e+4;
const ut INF=1<<30;
const ld eps=1e-6;
const LL p=7+1e+9;

int main(){
	int n;
	while(cin >> n && n){
		char teams[16], c;
		ppr res[16];
		REP(i,16){
			res[i] = make_pair(-64, make_pair(64, 64));
		}
		int r;
		REP(i,n){
			cin >> c;
			teams[i] = c;
			res[i].S.S = -i;
			REP(j,n-1){
				cin >> r;
				if(r == 0){
					res[i].F++;
				}
				else if(r == 1){
					res[i].S.F--;
				}
			}
		}
		sort(res, res + n, greater<ppr>());
		REP(i,n){
			cout << teams[-res[i].S.S] << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){

	int n;
	char t[10];
	int r;
	int win[10] = { 0 }, lose[10] = { 0 };

	while (cin >> n && n != 0){

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

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

			cout << t[i] << endl;
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    pair<pii,string> p[10];
    rep(i,n){
      int r;
      cin>>p[i].second;
      rep(j,n-1){
        cin>>r;
        if(r==0)
          p[i].first.first--;
        else if(r==1)
          p[i].first.second++;
      }
    }
    sort(p,p+n);
    rep(i,n)
      cout<<p[i].second<<endl;
  }
}

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;
		double r, w, f;
		priority_queue<pair<double,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 /= 100.0;
			double 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<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pi;

int main(){
  int n;
  while(cin >> n , n){
    Pi match[10];
    string team[10];
    for(int i=0;i<n;i++){
      cin >> team[i];
      match[i].first.first = 0; match[i].first.second = 0;
      match[i].second = i;
      for(int j=0;j<n-1;j++){
	int a; cin >> a;
	if(a == 0) match[i].first.first--;
	else if(a == 1) match[i].first.second++;
    }
    }
    sort(match,match+n);
    for(int i=0;i<n;i++){
      cout << team[match[i].second] << endl;
    }
  }
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<string>s(n);
	vector<int>p(n);
	vector<int>m(n);
	rep(i,n){
	  cin>>s[i];
	  int tmp;
	  rep(j,n-1){
	    cin>>tmp;
		if(!tmp)p[i]++;
		else if(tmp==1)m[i]++;
	  }
	}
	rep(i,n){
	  rep(j,n-i-1){
	    if(p[j]<p[j+1]||(p[j]==p[j+1]&&m[j]>m[j+1])){
		  swap(s[j],s[j+1]);
		  swap(m[j],m[j+1]);
		  swap(p[j],p[j+1]);
		}
	  }
	}
	rep(i,n)cout<<s[i]<<endl;
  }
}