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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<pair<int,string> > team(10);

int main() {
	int n;
	int score;
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			team[i].first=0;
			cin>>team[i].second;
//cout<<team[i].second<<endl;
			int j;
			for(j=0;j<n-1;j++){
				score=in();
				if(score==0)team[i].first+=100;
				if(score==2)team[i].first++;
//cout<<" "<<score<<endl;
			}
		}
		stable_sort(&team[0],&team[n],greater<pair<int,string> >());
		for(i=0;i<n;i++){
			cout<<team[i].second<<endl;
		}
	}
	return 0;
}

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

class Team
{
public:
	string name;
	int win,lost,InNo;

	Team(string name = string("str"), int win = 0, int lost = 0, int InNo = 0) :
	name(name),win(win),lost(lost),InNo(InNo){}

	bool operator < (const Team &ano) const
	{
		if(win != ano.win){
			return win > ano.win;
		}
		if(lost != ano.lost){
			return lost < ano.lost;
		}
		if(InNo != ano.InNo){
			return InNo < ano.InNo;
		}
		return name > ano.name;
	}

};

int n;

void solve()
{
	vector<Team> team(n);
	int res;

	for(int i = 0; i < n; i++){
		int win = 0, lost = 0;
		cin >> team[i].name;

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

			switch(res){
				case 0:
					win++;
				case 1:
					lost++;
			}
		}
		team[i].lost = lost;
		team[i].win = win;
	}

	sort(team.begin(), team.end() );

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

}

int main(void)
{
	while(cin >> n, n){
		solve();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

struct Team
{
    int win, lose, num;
    char name;

    Team () {}
    Team ( int win, int lose, char name, int num) : win(win), lose(lose), name(name), num(num) {}

    bool operator < ( const Team &d ) const
    {
        return ( win < d.win || win == d.win && (lose > d.lose || lose == d.lose && num > d.num));    }

    bool operator > ( const Team &d ) const
    {
        return ( !(*this < d) );
    }
};

int main()
{
    int N;
    Team data[15];

    while ( cin >> N, N ) {
        for ( int i = 0; i < N; i++ ) {
            int win = 0, lose = 0;
            char name;
            cin >> name;
            for ( int j = 0; j < N - 1; j++ ) {
                int d;
                cin >> d;
                switch ( d ) {
                    case 0 :
                        win++;
                        break;
                    case 1 :
                        lose++;
                        break;
                }
            }
            data[i] = Team ( win, lose, name, i );
        }
        sort ( data, data + N, greater<>());
        for ( int i = 0; i < N; i++ ) {
            cout << data[i].name << endl;
        }
    }

    return ( 0 );
}