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<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
struct Data
{
    char name;
    int win;
    int lose;
    bool operator<(const Data& d)const{
        if(win != d.win){
            return win > d.win;
        }
        else{
            return lose < d.lose;
        }
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        Data d[32];
        rep(i,n){
            char team;
            scanf(" %c",&team);
            int w = 0,l = 0;
            rep(j,n-1){
                int x;
                scanf("%d",&x);
                (x == 0) ? ++w : (x == 1) ? ++l :  l+=0;
            }
            d[i].name = team;
            d[i].win = w;
            d[i].lose  = l;
        }
        sort(d,d+n);
        rep(i,n){
            printf("%c\n",d[i].name);
        }
    }
    return 0;
}

C++: #include <iostream> 
#include <vector> 
#include <algorithm> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)  
	bool cmp(const pair<int,char> &a,const pair<int,char> &b){  
		return a.first > b.first; 
}

int main(void){ 
	int n;   
	while(cin >> n,n){       
		vector< pair<int,char> > data(n);      
		rep(i,n){          
			int sum = 0;     
			cin >> data[i].second;   
			rep(j,n-1){              
				int t;                
				cin >> t;              
				sum += (t==0?10:t==2?1:0);  
			} 
			data[i].first = sum; 
		}   
		stable_sort(data.begin(),data.end(),cmp);  
		rep(i,n){         
			cout << data[i].second << endl;       
		}
	}
	return 0;
}

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

using namespace std;

int main()
{ 
  while(1){
    int n;
    cin>>n;

    if(n == 0){
      break;
    }
    
    vector<pair<int,char>> total_result;
    int result;

    for(int i = 0;i < n;++i){
      int point = 0;
      char name;
      cin>>name;

      for(int j = 0;j < n - 1;++j){
        cin>>result;
        if(result == 0){
          point += 100;
        }
        else if(result == 2){
          point += 1;
        }
      }

      total_result.push_back(make_pair(point,name));
    }

    sort(total_result.begin(),total_result.end());
    reverse(total_result.begin(),total_result.end());

    for(int i = 0;i < n;++i){
      cout<<total_result[i].second<<endl;
    }
  }
  return 0;
}

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

typedef pair<int, int> P;
typedef pair<P, int> T;
int main(){
  int n, x;
  char c;
  while(cin >> n, n){
    map<T, char> mem;
    for(int i = 0;i < n;i++){
      T tmp = T(P(0, 0), i);
      cin >> c;
      for(int j = 1;j < n;j++){
	cin >> x;
	if(x == 0)tmp.first.first--;
	if(x == 1)tmp.first.second++;
      }
      mem[tmp] = c;
    }
    map<T, char>::iterator it = mem.begin();
    while(it != mem.end()){
      cout << it->second << endl;
      it++;
    }
  }
  return 0;
}

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]+=10;
				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<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(scanf("%d",&n), n){
    vector<pair<int,pair<int,pair<int,char> > > > v(n);
    REP(i,n){
      char c;
      scanf(" %c ",&c);
      int w=0, l=0;
      REP(j,n-1){
	int a; scanf("%d",&a);
	if(a == 0) w++;
	else if(a==1) l++;
      }
      v[i] = mp(-w, mp(l, mp(i, c)));
    }
    sort(v.begin(), v.end());
    REP(i,n)
      printf("%c\n",v[i].s.s.s);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)
int main(){
	int n;
	while(cin >> n,n){
		vector< pair<int,char> > data(n);
		rep(i,n){
			int sum = 0;
			cin >> data[i].second;
			rep(j,n-1){
				int t;
				cin >> t;
				sum += (t==0?10:t==2?1:0);
			}
			data[i].first = sum;
		}
		stable_sort(data.begin(),data.end(),greater< pair<int,char> >());
		rep(i,n){
			cout << data[i].second << endl;
		}
	}
}