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, draw).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[100];
	int i,j,temp;
	int w[100],l[100],a[100];
	char t[100],m;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			w[i]=0;
			l[i]=0;
			scanf(" %c",&t[i]);
			a[i]=i;
			for(j=0;j<n-1;j++){
				scanf("%d",&p[j]);
				if(p[j]==0){
					w[i]++;
				}
				if(p[j]==1){
					l[i]++;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(w[i]<w[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && l[i]>l[j]){
					temp=l[i];
					l[i]=l[j];
					l[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && l[i]==l[j] && a[i]>a[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%c\n",t[i]);
		}
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int team[n][n-1];
		char name[n];
		rep(i,n){
			cin>>name[i];
			rep(j,n-1){
				cin>>team[i][j];
			}
		}
		int win[n];
		int lose[n];
		rep(i,n){
			win[i]=0;
			lose[i]=0;
		}
		rep(i,n){
			rep(j,n-1){
				if(team[i][j]==0)win[i]++;
				else if(team[i][j]==1)lose[i]++;
			}
		}
		rep(i,n){
			for(int j=n-2;j>=i;j--){
				if(win[j+1]>win[j]){
					int alt=win[j];
					win[j]=win[j+1];
					win[j+1]=alt;
					alt=lose[j];
					lose[j]=lose[j+1];
					lose[j+1]=alt;
					char c=name[j];
					name[j]=name[j+1];
					name[j+1]=c;
				}else if(win[j+1]==win[j]){
					if(lose[j+1]<lose[j]){
						int alt=win[j];
						win[j]=win[j+1];
						win[j+1]=alt;
						alt=lose[j];
						lose[j]=lose[j+1];
						lose[j+1]=alt;
						char c=name[j];
						name[j]=name[j+1];
						name[j+1]=c;
					}
				}
			}
		}
		rep(i,n){
			cout<<name[i]<<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct data{
	string team;
	int win, lose, order;
};

bool cmp(data d1, data d2){
	if(d1.win != d2.win) return d1.win > d2.win;
	if(d1.lose != d2.lose) return d1.lose < d2.lose;
	return d1.order < d2.order;
}

signed main() {
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		vector<data> d(n);
		string s;
		int a, win, lose;
		rep(i, 0, n){
			cin >> s;
			win = 0;
			lose = 0;
			rep(j, 0, n - 1){
				cin >> a;
				if(a == 0) win++;
				else if(a == 1) lose++;
			}
			d[i].team = s;
			d[i].win = win;
			d[i].lose = lose;
			d[i].order = i;
		}
		sort(all(d), cmp);
		rep(i, 0, n){
			cout << d[i].team <<endl;
		}
	}
}

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;
}