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<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[11],f[11],g,h,i,j;
	char z[11][11],x[11];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			d[i]=0;
			f[i]=0;
			scanf("%s",z[i]);
			for(j=0;j<a-1;j++){
				scanf("%d",&s);
				if(s==0) d[i]++;
				if(s==1) f[i]++;
			}
		}
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(d[i]<d[j]){
					g=d[i];
					d[i]=d[j];
					d[j]=g;
					g=f[i];
					f[i]=f[j];
					f[j]=g;
					strcpy(x,z[i]);
					strcpy(z[i],z[j]);
					strcpy(z[j],x);
				}
				else if(d[i]==d[j]){
					if(f[i]>f[j]){
						g=d[i];
						d[i]=d[j];
						d[j]=g;
						g=f[i];
						f[i]=f[j];
						f[j]=g;
						strcpy(x,z[i]);
						strcpy(z[i],z[j]);
						strcpy(z[j],x);
					}
				}
			}
		}
		for(i=0;i<a;i++){
				printf("%s\n",z[i]);
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
struct result{
	char name;
	int win;
	int draw;
	int id;
};
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		pair<int, int>amax(-1, -1);
		vector<result>res;
		for (int i = 0; i < N; ++i) {
			char c; cin >> c;
			pair<int, int>score;
			for (int j = 0; j < N - 1; ++j) {
				int a; cin >> a;
				if (a == 0)score.first++;
				else if (a == 2)score.second++;
			}
			res.push_back(result{ c,score.first,score.second,i });

		}
		sort(res.begin(), res.end(), [](const result&l, const result&r) {
			return l.win == r.win ? l.draw == r.draw ? l.id<r.id : l.draw>r.draw : l.win>r.win;
		});
		for (auto r : res) {
			cout << r.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+=2;
				else if(r==2) point++;
				else --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<stdio.h>
int main()
{
	int i, n, ruito[12][11] = { 0 }, debu[12][4] = { 0 }, masatoy, k, j, temp;
	char str[20];
	char baka[2];
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%s", &str[i]);
		for (k = 1; k <= n - 1; k++) {
			scanf("%d", &ruito[i][k]);
		}
	}
	for (i = 1; i <= n; i++) {
		for (k = 1; k <= n - 1; k++) {
			if (ruito[i][k] == 0) {
				debu[i][1]++;
			}
			else if (ruito[i][k] == 1) {
				debu[i][2]++;
			}
			else {
				debu[i][3]++;
			}
		}
	}
	for (i = 1; i < n; i++) {
		for (j = n; j > i; j--) {
			if (debu[j][1] > debu[j-1][1]) {
				temp = debu[j][1];
				debu[j][1] = debu[j - 1][1];
				debu[j - 1][1] = temp;
				baka[1] = str[j];
				str[j] = str[j - 1];
				str[j - 1] = baka[1];
			}
		}
	}
	for (i = 1; i < n; i++) {
		for (j = n; j > i; j--) {
			if (debu[j][1] == debu[j - 1][1]) {
				if (debu[j][2] < debu[j - 1][2]) {
					temp = debu[j][1];
					debu[j][1] = debu[j - 1][1];
					debu[j - 1][1] = temp;
					baka[1] = str[j];
					str[j] = str[j - 1];
					str[j - 1] = baka[1];
				}
			}
		}
	}
	for (i = 1; i <= n; i++) {
		printf("%c\n", str[i]);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
        while(true){
                int n;
                char t;
                int r;
                char x[10];
                cin >> n;
                if(n==0)
                        break;
                int win[10],lose[10];
                for(int i=0 ;i<10 ;i++){
                                win[i] = 0;
                                lose[i] = 0;
                }
                for(int i=0 ;i<n ;i++){
                        cin >> t;

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

                        }
                        x[i] = t;
                }
                char y=0;
				int z=0;

                for(int i=0 ;i<n-1 ;i++){
                                for(int j=i+1 ;j<n ;j++){
                                if(win[i] < win[j]){
                                        z=win[i];
                                        win[i]=win[j];
                                        win[j]=z;
                                        y=x[i];
                                        x[i]=x[j];
                                        x[j]=y;
                                }
                                else if(win[i] == win[j]){
                                        if(lose[i] > lose[j]){
                                                z=win[i];
                                                win[i]=win[j];
                                                win[j]=z;
                                                y=x[i];
                                                x[i]=x[j];
                                                x[j]=y;
                                        }
                                }
								else if(win[i] == win[j] && lose[i] == lose[j]){
									if(x[i] > x[j]){
										z=win[i];
                                        win[i]=win[j];
                                        win[j]=z;
										y=x[i];
                                        x[i]=x[j];
                                        x[j]=y;
									}
								}
                        }
                }

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