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 <climits>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vs names(n);
		vvi table(n,vi(n));
		rep(i,n){
			cin>>names[i];
			rep(j,n){
				if(i==j)
					continue;
				cin>>table[i][j];
			}
		}
		vi scores(n);
		rep(i,n) rep(j,n){
			if(i==j)
				continue;
			if(table[i][j]==0)
				scores[i]+=100;
			else if(table[i][j]==1)
				scores[i]-=1;
		}
		rep(i,n)
			for(int j=i;j>0;j--)
			if(scores[j-1]<scores[j]){
				swap(names[j-1],names[j]);
				swap(scores[j-1],scores[j]);
			}
		rep(i,n)
			cout<<names[i]<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,score;
	int tokuten[10];
	char name[10];
	while(1){
		for(int i=0;i<10;i++)
			tokuten[i] = 0;
		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] += 100;
				else if(score == 1)
					tokuten[i]--;
			}
		}
		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<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int main()
{
	while (1) 
	{
		int a;
		cin >> a;
		if (a == 0)break;
		map<int, 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--;
			}
			cout << c << endl;
			s.insert(pair<int, string>(c, b));
		}
		for (auto q = s.begin(); q != s.end(); q++) {
			cout << q->second << endl;
		}
	}
}

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

typedef pair<char, int> pii;

bool fanc(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			char c;
			int num, sum = 0;
			cin >> c;
			
			for (int j = 0; j < n - 1; j++){
				cin >> num;
				sum += num != 2 ? num : 0;
				     //   ?????¶     ???   ???
			}
			
			p[i] = make_pair(c, sum);
		}
		
		sort(p.begin(), p.end(), fanc);
		
		for (int i = 0; i < n; i++){
			cout << p[i].first << endl;
		}
	}
	
	return (0);
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
#define MP make_pair
int main(){
	int n;
	for(;;){
		scanf("%d\n",&n);
		if(n==0) break;
		pair<pair<int,int>,pair<int,char> > ar[10];
		char c;
		int r;
		for(int i=0;i<n;i++){
			scanf("%c",&c);
			int win=0,lose=0;
			for(int j=0;j<n-1;j++){
				scanf(" %d",&r);
				if(r==0) win++;
				if(r==1) lose++;
			}
			ar[i]=MP(MP(-win,lose),MP(i,c));
			scanf("\n");
		}
		sort(ar,ar+n);
		for(int i=0;i<n;i++){
			printf("%c\n",ar[i].second.second);
		}
	}
}

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

bool cmp(pair<string,pair<int,int> > a, pair<string,pair<int,int> > b){
	a.second > b.second;
}

int main(){
	
	int n;
	int t;
	while(cin >> n && n){
		vector<pair<string,pair<int,int> > > team(n);
		
		for(int i=0;i<n;i++){
			cin >> team[i].first;
			for(int j=0;j<n-1;j++){
				cin >> t;
				if(t==0)team[i].second.first++;
				if(t==1)team[i].second.second--;
			}
		}
		stable_sort(team.begin(),team.end(),cmp);
		
		for(int i=0;i<team.size();i++){
			cout << team[i].first << endl;
		}
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	char ti[10000];
	int ho[10000];
	while(1){
		int n,win[10000]={},lose[100000]={},blow[100000]={};
	
		cin >> n;
		if(n == 0) break;
		for(int i=0;i < n;i++){
			cin >> ti[i];
			for(int j=0;j<n-1;j++){
				cin >> ho[j];
				if(ho[j] == 0) win[i]+=1;
				if(ho[j] == 1) lose[i]+=1;
			}
		}for(int i=0;i<n;i++){
			for(int j=0;j+1<n;j++){
				if(win[j] < win[j+1] || (win[j]==win[j+1] && lose[j] > lose[j+1]) ){
					swap(lose[j],lose[j+1]);	
					swap(win[j],win[j+1]);	
					swap(ti[j],ti[j+1]);
				}
			}
		}for(int i=0;i<n;i++){
		 cout << ti[i] << endl;	
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int N;
string S[20];
int W[20];int L[20];
bool F[20];
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		for(int i=0;i<N;i++)F[i]=true;
		for(int i=0;i<N;i++){
			W[i]=0;L[i]=0;
		}
		for(int i=0;i<N;i++){
			cin >> S[i];
			for(int j=0;j<N-1;j++){
				int n;
				scanf("%d",&n);
				if(n==0)W[i]++;
				else if(n==1)L[i]++;
			}
		}
		for(int i=0;i<N;i++){
			int maxw=-1;int maxwi;bool FF=true;
			for(int j=0;j<N;j++){
				if(!F[j])continue;
				if(maxw<W[j]){
					
					maxw=W[j];maxwi=j;FF=true;
				}
				else if(maxw==W[j]){
					FF=false;
				}
			}
			if(FF){
				cout << S[maxwi] << "\n";
				F[maxwi]=false;
			}
			else{
				int minl=20;int minli;
				for(int j=0;j<N;j++){
					if(!F[j])continue;
					if(maxw!=W[j])continue;
					if(minl>L[j]){
						minl=L[j];
						minli=j;
					}
				}
				cout << S[minli] << "\n";
				F[minli]=false;
			}
		}
		
	}
}