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 <iostream>
#include <algorithm>
using namespace std;

typedef struct {
	char t;
	int pt[10];
	int win;
	int lose;
} GAME;

int main()
{
	GAME game[10];
	int n;

	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			game[i].win = game[i].lose = 0;
			cin >> game[i].t;
			for (int j = 0; j < n - 1; j++){
				cin >> game[i].pt[j];
				if (game[i].pt[j] == 0){
					game[i].win++;
				}
				else if (game[i].pt[j] == 1){
					game[i].lose++;
				}
			}
		}

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (game[j].win > game[j - 1].win){
					swap(game[j], game[j - 1]);
				}
				else if (game[j].win == game[j - 1].win && game[j].lose < game[j - 1].lose){
					swap(game[j], game[j - 1]);
				}
			}
		}

		for (int i = 0; i < n; i++){
			cout << game[i].t << endl;
		}
	}

	return (0);
}

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<pair<int,int>, pair<int,string> > > v;
		for(int i = 0; i < n; i++) {
			string s;
			int win = 0;
			int lose = 0;
			cin >> s;
			for(int j = 0; j < n - 1; j++) {
				int t;
				cin >> t;
				if(t == 0)
					win--;
				else if(t == 1)
					lose++;
			}
			v.push_back(pair<pair<int,int>,pair<int,string> >(pair<int,int>(win, lose), pair<int,string>(i,s)));
		}
		sort(v.begin(), v.end());
		for(int i = 0; i < v.size(); i++) {
			cout << v[i].second.second << endl;
		}
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,char> P;
typedef pair<int,P> PP;

bool compare(PP a,PP b){
  return a.first > b.first;
}

int main(){
  int n,res[10];
  char ch;

  while(cin >> n ,n){
    vector<PP> v;
    for(int i = 0 ; i < n ; i++){
      int sum = 0 , f = 0;
      cin >> ch;
      for(int j = 0 ; j < n-1 ; j++){
	cin >> res[j];
	if(res[j]==0) sum += 5;
	else if(res[j]==2) sum++;
	else f++;
      }  
      v.push_back(PP(sum,P(f,ch))); 
    }
    sort(v.begin(),v.end(),compare);
    for(int i = 0 ; i < n ; i++) cout << v[i].second.second << endl;
  }

  return 0;
}

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

using namespace std;

struct team {
	char name;
	int w;
	int l;
	int d;
};

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		team t[10];
		int a;
		for (int i = 0; i < n; i++) {
			cin >> t[i].name;
			t[i].w = t[i].l = t[i].d = 0;
			for (int j = 0; j < n-1; j++) {
				cin >> a;
				if (a == 0) {
					t[i].w++;
				} else if (a == 1) {
					t[i].l++;
				} else {
					t[i].d++;
				}
			}
		}
		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (t[j].w < t[j+1].w) {
					swap(t[j], t[j+1]);
				} else if (t[j].w == t[j+1].w) {
					if (t[j].l > t[j+1].l) {
						swap(t[j], t[j+1]);
					}
				}
			}
		}
		for (int i = 0; i < n; i++) {
			cout << t[i].name << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,j,h,w[10],l[10],t,u[10];
	char q[11],g;
	while(1){
		for(i=0;i<10;i++){
			w[i]=0;
			l[i]=0;
		}	
		scanf("%d",&n);
		if(n<2) break;
			for(i=0;i<n;i++){
				u[i]=i;
				scanf(" %c",&q[i]);
				for(j=0;j<n-1;j++){
					scanf("%d",&h);
					if(h==0){
						w[i]++;
					}
					if(h==1){
						l[i]++;
					}
				}
			}
			for(i=0;i<n-1;i++){
				for(j=i+1;j<n;j++){
					if(w[i]<w[j]||(w[i]==w[j]&&l[i]>l[j])||(w[i]==w[j]&&l[i]==l[j]&&u[i]>u[j])){
						t=w[i];
						w[i]=w[j];
						w[j]=t;
						
						t=l[i];
						l[i]=l[j];
						l[j]=t;
						
						t=u[i];
						u[i]=u[j];
						u[j]=t;
					
						g=q[i];
						q[i]=q[j];
						q[j]=g;
					}				
				}	
			}		
			for(i=0;i<n;i++){			
				printf("%c\n",q[i]);
			}
	}
	return 0;
}

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

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		float r, w, f;
		priority_queue<pair<float,char>> results;
		for (int i = 0; i < n;++i) {
			cin >> name;
			w = 0.0, f = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				cin >> r;
				if (r == 0)w++;
				if (r == 1)f++;
			}
			f /= 1000.0;
			float result = w - f;
			results.push(make_pair(result,name));
		}
		for (int i = 0; i < n; ++i) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long int i,j,k,n,a,b,sum;
	while(1) {
		cin>>n;
		vector<pair<long long int,char> > pp(n);
		
		if(n==0) break;
		for(i=0;i<n;i++) {
			cin>>pp[i].second;
			sum=0;
			for(j=0;j<n-1;j++) {
				cin>>a;
				if(a==0) sum+=10000000;
				if(a==1) sum-=1;
			}
			pp[i].first=sum;
		}
		sort(pp.begin(),pp.end());
		for(i=n-1;i>=0;i--) {
			cout<<pp[i].second<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct data{
    char name;
    int win;
    int lose;
};

int main(){
    int n;
    struct data data[15];
    while(cin >> n, n){
        rep(i,n){
            cin >> data[i].name;
            data[i].win = data[i].lose = 0;
            rep(j,n - 1){
                int inp;
                cin >> inp;
                if(inp == 0)
                    data[i].win++;
                else if(inp == 1)
                    data[i].lose++;
            }
        }
        rep(i,n){
            rep(j,n - 1){
                if(data[j].win < data[j + 1].win){
                    struct data g = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = g;
                }
                if(data[j].win == data[j + 1].win){
                    if(data[j].lose > data[j + 1].lose){
                        struct data g = data[j];
                        data[j] = data[j + 1];
                        data[j + 1] = g;
                    }
                }
            }
        }
        rep(i,n){
            cout << data[i].name << endl;
        }
    }
}