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 <iostream>
#include <vector>
#include <string>
using namespace std;
 
int main(){
  int n;
 
  while(1) {
  cin >> n;
  if(n == 0) break;
  vector <int> v,lo;
 
  string str[10];
  v.resize(n);
  lo.resize(n);
  for(int i=0;i<n;i++) v[i] = lo[i] = 0;
   
  int a;
  for(int i=0;i<n;i++) {
    cin >> str[i];
    for(int j=0;j<n-1;j++) {
      cin >> a;
      if(a ==0) v[i]++;
      else if(a == 1) lo[i]++;
       
    }
  }
   
  string t;
 
  for(int i=0;i<n-1;i++) {
    for(int j=n-1;j>i;j--) {
      if(v[j] > v[j-1]) {
    t = str[j];
    str[j] = str[j-1];
    str[j-1]  = t;
     
    a = v[j];
    v[j] = v[j-1];
    v[j-1] = a;
     
    a = lo[j];
    lo[j] = lo[j-1];
    lo[j-1] = a;
     
      } else if(v[j] == v[j-1] && lo[j] < lo[j-1]) {
    t = str[j];
    str[j] = str[j-1];
    str[j-1] = t;
 
    a = lo[j];
    lo[j] = lo[j-1];
    lo[j-1] = a;
      }
    }
  }
      for(int i=0;i<n;i++) cout << str[i] << endl;
 
  } 
 
 
  return 0;
}

C++: #include<iostream>

using namespace std;

typedef struct{
  int win;
  int lose;
  char name;
}Info;

int main(){

  int n;
  while(cin >> n && n){
    Info data[n];
    for(int i = 0; i < n; i++) data[i].lose = data[i].win = 0;

    for(int i = 0; i < n; i++){
      cin >> data[i].name;
      for(int j = 0; j < n-1; j++){
	int num;
	cin >> num;
	if(num == 0) data[i].win++;
	if(num == 1) data[i].lose++;
      }
    }
    
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n-i-1; j++){
	if(data[j].win == data[j+1].win && data[j].lose > data[j+1].lose) swap(data[j],data[j+1]);
	if(data[j].win < data[j+1].win) swap(data[j],data[j+1]);
      }
    for(int i = 0; i < n; i++) cout << data[i].name << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[100];
	int i,j,temp;
	int w[100],l[100],a[100];
	char t[100],m;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			w[i]=0;
			l[i]=0;
			scanf(" %c",&t[i]);
			a[i]=i;
			for(j=0;j<n-1;j++){
				scanf("%d",&p[j]);
				if(p[j]==0){
					w[i]++;
				}
				if(p[j]==1){
					l[i]++;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(w[i]<w[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && a[i]>a[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%c\n",t[i]);
		}
		scanf("%d",&n);
	}
	return 0;
}

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

vector<PC> table;//??????????????????????????????
int n, co[3], num;
char c;

bool flag(PC a, PC b){
	if (a.first.first == b.first.first){
		return a.first.second < b.first.second;
	}
	return a.first.first > b.first.first;
}

int main(){
	while (cin >> n&&n){
		REP(i, n){
			cin >> c;
			co[0] = co[1] = 0;
			REP(i, n - 1){
				cin >> num;
				co[num]++;
			}
			table.push_back(PC(P(co[0], co[1]), c));
		}
		sort(ALL(table), flag);
		REP(i, n){
			cout<< table[i].second << endl;
		}
		table.clear();
	}
}

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

struct team {
	char n[2];
	int w = 0, l = 0, t = 0;

	bool operator < (const team & rhs) const {
		return w > rhs.w || (w == rhs.w && l < rhs.l);
	}
};

int main()
{	
	int n;

	cin >> n;

	while (n > 0) {
		team tm[10];

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

				if (r == 0)
					tm[i].w++;
				else if (r == 1)
					tm[i].l++;
				else if (r == 2)
					tm[i].t++;
			}
		}

		sort(tm, tm + n);

		for (int i = 0; i < n; i++)
			cout << tm[i].n << endl;

		cin >> n;
	}
	
	return 0;
}

C++: #include<iostream>
#include<utility>
#include<algorithm>
#include<queue>

using namespace std;

priority_queue<pair<pair<int, int>,char>> results;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		int win, lose;
		for (int i = 0; i < n;++i) {
			cin >> name;
			win = 0;lose = 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;
}