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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		pair<int, char> scores[10];
		for (int i = 0; i < n; ++i)
		{
			char name;
			scanf(" %c", &name);
			int w, l;
			w = l = 0;
			for (int j = 1; j < n; ++j)
			{
				int t;
				scanf("%d", &t);
				if (t == 0)
					++w;
				else if (t == 1)
					++l;
			}
			scores[i] = make_pair(w*10000 - l*100 + 10-i, name);
		}
		sort(scores, scores+n, greater<pair<int, char> >());
		for (int i = 0; i < n; ++i)
			printf("%c\n", scores[i].second);
	}

	return 0;
}

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

int main()
{
	while (1) 
	{
		int a;
		cin >> a;
		if (a == 0)break;
		map<double, string>s;
		for (int p = 0; p < a; p++) {
			string b;
			cin>>b;
			int c = 0;
			for (int d = 0; d <(a-1); d++) {
				int e;
				cin >> e;
				if (e == 0)c -= 100;
				else if (e == 2)c--;
			}
			s.insert(pair<double, string>(c+p/(double)100, b));
		}
		for (auto q = s.begin(); q != s.end(); q++) {
			cout << q->second << endl;
		}
	}
}

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

struct Team {
    char t;
    int win, lose;
    bool operator < (const Team& team_) const {
        return win == team_.win ? lose > team_.lose : win < team_.win;
    }
};

Team team[11];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(cin >> n && n){
        for(int i = 0; i < n; ++i){
            cin >> team[i].t;

            for(int j = 0; j < n - 1; ++j){
                int a;
                cin >> a;
                if(a == 0) ++team[i].win;
                if(a == 1) ++team[i].lose;
            }
        }

        sort(team, team + n);

        for(int i = n - 1; i >= 0; --i){
            cout << team[i].t << endl;
        }
    }

    return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

struct team
{
	string id;
	int win;
	int lose;

	team(string s,int w,int l) : id(s),win(w),lose(l) {}

	bool operator < (const team& t) const{
		return win == t.win ? lose < t.lose : win > t.win;
	}
};

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<team> v;

		rep(i,n)
		{
			string s;
			cin >> s;
			
			int w = 0;
			int l = 0;
			
			rep(j,n-1)
			{
				int temp;
				cin >> temp;

				if(temp == 0) w++;
				else if(temp == 1) l++;
			}

			cout << "t:" << s << " w:" << w << " l:" << l << endl;
			v.push_back(team(s,w,l));
		}

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


		rep(i,v.size())
		{
			cout << v[i].id <<  endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;

int main(){

  int n;
  char c[11];
  int dat[11][11];
  typedef pair < int, pair < int, char > > P; //win, lose, name
  P team[11];

  while(cin >> n, n){

    for(int i=0;i<n;i++){
      cin >> team[i].S.S;
      for(int j=0;j<n-1;j++){
	cin >> dat[i][j];
	if(dat[i][j] == 1) team[i].S.F--;
	if(dat[i][j] == 0) team[i].F++;
      }
    }
    
    sort(team, team+n);
    reverse(team, team+n);

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

C++: #include <iostream>
#include <cstdio>
#include <cstring>

typedef struct{
	char name[100];
	int win;
	int lose;
	int prior;
}team;

void swap(team *p, team *q){
	team tmp = *p;
	*p = *q;
	*q = tmp;
}

int main(){
	while(1){
		int n, a;
		char c[100];
		team t[10];
		
		scanf(" %d", &n);
		if(n==0) break;
	
		for(int i=0; i<n; i++){
			scanf(" %s", c);
			strcpy(t[i].name, c);
			t[i].win=0;
			t[i].lose=0;
			t[i].prior=i;
			
			for(int j=0; j<n-1; j++){
				scanf(" %d", &a);
				if(a==0) ++t[i].win; 
				else if(a==1) ++t[i].lose;
			}
		}
		
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if( (t[i].win > t[j].win) || (t[i].win==t[j].win && t[i].lose < t[j].lose) ||  (t[i].win==t[j].win && t[i].lose==t[j].lose && t[i].prior < t[j].prior) )
					swap(&t[i], &t[j]);
			}
		}
	
		for(int i=0; i<n; i++)
			printf("%s\n", t[i].name);

	}

	return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

struct PROFILE {
    char name[5];
    int win_num;
    int lose_num;
};

bool operator<(const PROFILE& left, const PROFILE& right)
{
    return left.win_num > right.win_num;
}

int main(void)
{
    struct PROFILE team[10];
    int n;
    
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < 10; i++){
           team[i].win_num = team[i].lose_num = 0;
        }
        
        int tmp;
        for (int i = 0; i < n; i++){
            scanf("%s", team[i].name);
            for (int j = 0; j < (n - 1); j++){
                scanf("%d", &tmp);
                if (tmp == 0) team[i].win_num++;
                else if (tmp == 1) team[i].lose_num++;
            }
        }
        
        sort(team, team + n);
        
        for (int i = 0; i < n; i++){
            printf("%c\n", team[i].name[0]);
        }
    }
    
    return (0);
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(void){

	int n;
	char t[10];
	int r;
	int win[10] = { 0 }, lose[10] = { 0 };
	memset(win, 0, sizeof(win)); memset(lose, 0, sizeof(lose));

	while (cin >> n && n != 0){

		for (int i = 0; i < n; i++){
			cin >> t[i];
			for (int j = 0; j < n - 1; j++){
				cin >> r;
				if (r == 0) win[i]++;
				if (r == 1) lose[i]++;
			}
		}

		bool flg = true;
		int i = 0;
		while (flg){
			flg = false;
			for (int j = n - 1; j >= i + 1; j--){
				if (win[j] > win[j - 1]){
					swap(win[j], win[j - 1]); swap(lose[j], lose[j - 1]); swap(t[j], t[j - 1]);
					flg = true;
				}
				else if (win[j] == win[j - 1]){
					if (lose[j] < lose[j - 1]){
						swap(win[j], win[j - 1]); swap(lose[j], lose[j - 1]); swap(t[j], t[j - 1]);
						flg = true;
					}
				}
			}
			i++;
		}
		for (i = 0; i < n;i++){
			cout << t[i] << endl;
		}
	}
}