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 <bits/stdc++.h>
using namespace std;
typedef pair<char,pair<int,int> > p;
int main() {
	int n;
	while(cin>>n,n){
		vector<p>a;
		for(int i=0;i<n;i++){
			p data;cin>>data.first;
			data.second.first=0;
			data.second.second=0;
			for(int j=0;j<n-1;j++){
				int p;cin>>p;
				if(p==0)data.second.first++;
				else if(p==1)data.second.second++;
			}
			a.push_back(data);
		}
		for(int i=0;i<n;i++){
			int f=0;
			for(int j=1;j<a.size();j++){
				if(a[j].second.first>a[f].second.first)f=j;
				else if(a[j].second.first==a[f].second.first&&a[j].second.first<a[f].second.first)f=j;
			}
			cout<<a[f].first<<endl;
			a.erase(a.begin()+f);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
pair<int, string>a[100000];
int n, sum, p;
int main() {
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a[i].second;
			sum = 0;
			for (int j = 0; j < n - 1; j++) {
				cin >> p;
				if (p == 0) { sum += 10000; }
				if (p == 2) { sum += 1; }
			}
			a[i].first = sum;
		}
		sort(a, a + n);
		for (int i = n - 1; i >= 0; i++) {
			cout << a[i].second << endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,score;
	int tokuten[10]={0};
	char name[10];
	while(1){
		cin >> n;
		if(n == 0)
			break;
		for(int i=0;i<n;i++){
			cin >> name[i];
			for(int j=0;j<n-1;j++){
				cin >> score;
				if(score ==0)
					tokuten[i] += 2;
				else if(score == 2)
					tokuten[i] += 1;
			}
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(tokuten[i] < tokuten[j]){
					int T = tokuten[i];
					tokuten[i] = tokuten[j];
					tokuten[j] = T;
					char TT = name[i];
					name[i] = name[j];
					name[j] = TT;
				}
			}
		}
		for(int i=0;i<n;i++)
			cout << name[i] << endl;
	}
	return 0;
}

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