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 <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<pair<int, int>, pair<int, string> > > team(n);
        for(int i=0; i<n; ++i){
            team[i].second.first = -i;
            cin >> team[i].second.second;
            for(int j=0; j<n-1; ++j){
                int a;
                cin >> a;
                if(a == 0)
                    ++ team[i].first.first;
                else if(a == 1)
                    -- team[i].first.second;
            }
        }
        sort(team.rbegin(), team.rend());

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
struct box{
	int win,lose;
	string s;
};
int cmp(const box &a,const box &b){
	if(a.win==b.win){
		return a.lose<b.lose;
	}else{
		return a.win>b.win;
	}
}
int main(){
	int n,w,l,p;
	string t;
	vector<box> vec;
	box pre;
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>t;
			w=0;
			l=0;
			for(int j=0;j<n-1;j++){
				cin>>p;
				if(p==0)
				w++;
				else if(p==1)
				l++;
			}
			pre.win=w;
		pre.lose=l;
		pre.s=t;
		vec.push_back(pre);
		}
		stable_sort(vec.begin(),vec.end(),cmp);
		for(int i=0;i<n;i++)
		cout<<vec[i].s<<endl;
		vec.clear();
	}
	return 0;
}

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

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());

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

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

struct point{
  int win, lose, draw;
  string name;

  void clear()
  {
    win = lose = draw = 0;
    name = "";
  }
};

bool operator<(point a, point b)
{
  return (a.win != b.win)? a.win > b.win: a.lose < b.lose;
}

int main()
{
  multiset<point> team;
  multiset<point>::iterator it;
  int n, i, j, m;
  string s;
  point t;
  while (cin>>n, n) {
    team.clear();
    for (i = 0; i < n; i++) {
      t.clear();
      cin>>s;
      t.name = s;
      for (j = 0; j < n-1; j++) {
	cin>>m;
	if (m == 0) t.win++;
	if (m == 1) t.lose++;
	if (m == 2) t.draw++;
      }
      team.insert(t);
    }
    for (it = team.begin(); it != team.end(); it++)
      cout<<(*it).name<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int n;
	
	while(true){
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		string str[100];
		
		int score[100];
		
		for(int i = 0; i < n; i++){
			cin >> str[i];
			score[i] = 0;
			for(int j = 0; j < n - 1; j++){
				int hoge;
				cin >> hoge;
				if(hoge == 0){
					score[i] += 100;
				}else if(hoge == 1){
					score[i] -= 1;
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n - 1; j++){
				if(score[j] < score[j + 1]){
					swap(score[j], score[j + 1]);
					swap(str[j], str[j + 1]);
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			cout << str[i] << endl;
		}
		
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int,pair<int,int> > P;
int n,r;
string t[10];
P p[10];

int main(){
	while(cin>>n){
		if(!n)return 0;
		for(int i=0;i<n;i++){
			cin>>t[i];
			p[i].first=0;
			p[i].second.first=0;
			p[i].second.second=i;
			for(int j=0;j<n-1;j++){
				cin>>r;
				if(!r)p[i].first--;
				if(r==1)p[i].second.first++;
			}
		}
		sort(p,p+n);
		for(int i=0;i<n;i++)cout<<t[p[i].second.second]<<endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i, m, n) for(int i=(m);i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
typedef pair<Pii, char> Pic;
typedef vector<int> Vi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};


int main()
{
  int n;

  while( cin >> n, n ) {
    priority_queue<Pic> q;

    Rep(i, n) {
      char c;
      int win = 0, los = 0;
      cin >> c;
      
      Rep(j, n-1) {
	int a;
	cin >> a;
	if( a == 0 ) win++;
	else if( a == 1 ) los++;
      }

      q.push( Pic(Pii(win, -los), c) );
    }

    while( !q.empty() ) {
      cout << q.top().sc << endl;
      q.pop();
    }

  }

}