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>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<pair<pair<int,int>,pair<int,char> > > v;
		for(int i = 0; i < n; i++){
			char ch;
			int w,l;
			w=l=0;
			cin>>ch;
			for(int j = 0; j < n-1; j++){
				int t;
				cin>>t;
				if(t==0)
					w++;
				else if(t==1)
					l++;
			}

			v.push_back(make_pair(make_pair(-w,l),make_pair(i,ch)));
		}
		sort(v.begin(),v.end());
		for(int i = 0; i < v.size(); i++){
			cout<<v[i].second.second<<endl;
		}
	}


	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        vi v(7,0);
        rep(i,n){
            int gotiusa_is_a_god_especially_tiya;
            cin>>gotiusa_is_a_god_especially_tiya;
            if(gotiusa_is_a_god_especially_tiya>=60)gotiusa_is_a_god_especially_tiya=60;
            v[gotiusa_is_a_god_especially_tiya/10]++;
        }
        rep(i,7)cout<<v[i]<<endl;
    }
}

C++: // 2011/02/06 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

class Team{
	public:
		char name;
		int  win;
		int  defeat;
		int  draw;

		bool operator < (const Team& t) const
		{
			if(win==t.win)
				return defeat<t.defeat;
			else
				return win>t.win;
		}
};

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		Team T[10];
		for(int i=0; i<n; i++){
			cin >> T[i].name;
			T[i].win = T[i].defeat = T[i].draw = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;
				if(r==0)
					T[i].win++;
				else if(r==1)
					T[i].defeat++;
				else if(r==2)
					T[i].draw++;
			}
		}

		stable_sort(T, T+n);

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

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <sstream>
#include<vector>
using namespace std;


int main(void){
	multimap<int,char,greater<int> > team;
	char t;
	int n;

	while(1)
	{
		cin>>n;
		if(!n) break;
		
		for(int j=0; j<n; j++)
		{
			cin>>t;
			int point=0,r;
			
			for(int i=0; i<n-1; i++)
			{
				cin>>r;
				if(r==0) ++point;
				else if(r==1) --point;
			}
			team.insert( make_pair( point,t) );
		}

		for(multimap<int,char,greater<int> >::iterator it=team.begin(); it != team.end(); ++it)
			cout<<(*it).second<<endl;
		team.clear();
	}
	return 0;
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
typedef pair<pii,pair<int,string> > P;
int main(){
	int n;
	while(cin>>n,n){
		int t =n;
		priority_queue<P> data;
		//while(!data.empty())data.pop();
		while(t--){
			string str;
			cin>>str;
			int v,l,d;
			v = l = d= 0;
			for(int i =1;i < n;i++){
				int x;
				cin>>x;
				if(x==0){
					v++;
				}else if(x==1){
					l++;
				}else{
					d++;
				}
			}
			data.push(P(mp(v,-l),mp(t,str)));
		}
		while(!data.empty()){
			cout <<data.top().second.second<<endl;
			data.pop();
		}
	}
	return 0;
}

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

class T
{
public:
	string n;
	int w,d;

	T(string n, int w, int d)
	:n(n),w(w),d(d)
	{}
	
	bool operator<(const T& t) const
	{
		if(w!=t.w) return w>t.w;
		return d<t.d;
	}

};

int main()
{
	int N;
	while(cin >> N, N)
	{
		vector<T> v;
		for(int j=0; j<N; j++)
		{
			string n;
			int w=0, d=0;
			cin >> n;
			for(int i=0; i<N-1; i++)
			{
				int t;
				cin >> t;
				if(t==0) w++;
				if(t==1) d++;
			}
			v.push_back(T(n,w,d));
		}
		
		sort(v.begin(), v.end());
		for(int i=0; i<v.size(); i++)
			cout << v[i].n << endl;
	}
}