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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	vector<pair<int,char> > data[11];
	int n;
	while(cin>>n,n){
		rep(i,n){
			int w=0,l=0;
			char t;
			cin>>t;
			rep(j,n-1){
				int a;
				cin>>a;
				if(a==0)w++;
				else if(a==1)l++;
			}
			data[w].push_back(make_pair(l,t));
		}
		for(int i=n-1;i>=0;i--){
			if(data[i].size()>0){
				sort(data[i].begin(),data[i].end());
				for(int j=0;j<data[i].size();j++){
					cout<<data[i][j].second<<endl;
				}
			}
		}
	}
}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

struct Data
{
	char c;
	int win;
	int lose;
	Data() : win(0), lose(0) {}
	bool operator< (const Data& d)const{
		return win!=d.win ? win>d.win : lose<d.lose;
	}
};

int main()
{
	int n;
	while(scanf("%d", &n), n){
		Data data[10];
		rep(i, n){
			scanf(" %c", &data[i].c);
			rep(j, n-1){
				int tmp;
				scanf("%d", &tmp);
				if(tmp == 0)
					++data[i].win;
				else if(tmp == 1)
					++data[i].lose;
			}
		}
		sort(data, data+n);
		rep(i, n)
			printf("%c\n", data[i].c);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n, a, d[10], e[10]; char c[10];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> c[i]; d[i] = 0, e[i] = 0;
			for (int j = 0; j < n - 1; j++) {
				scanf("%d", &a);
				if (a == 0) d[i]++;
				if (a == 1) e[i]++;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (d[i] < d[j]) {
					swap(c[i], c[j]);
					swap(d[i], d[j]);
					swap(e[i], e[j]);
				}
				else if (d[i] == d[j] && e[i] > e[j]) {
					swap(c[i], c[j]);
					swap(d[i], d[j]);
					swap(e[i], e[j]);
				}
			}
		}
		for (int i = 0; i < n; i++) printf("%c\n", c[i]);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void){
	int n,r,t[3][10],i,a,f;
	char N[10][10];
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i!=n;i++){
			t[0][i]=i;
			t[1][i]=0;
			t[2][i]=0;
		}
		for(i=0;i!=n;i++){
			scanf("%s",&N[i]);
			for(a=0;a!=n-1;a++){
				scanf("%d",&r);
				if(r==0){
					t[1][i]++;
				}
				else if(r==1){
					t[2][i]++;
				}
			}
		}
		for(i=0;i!=n;i++){
			for(a=i;a!=n;a++){
				if(t[1][i]<t[1][a]){
					for(f=0;f!=3;f++){
						r=t[f][i];
						t[f][i]=t[f][a];
						t[f][a]=r;
					}
				}
				else if(t[1][i]==t[1][a]){
					if(t[2][i]>t[2][a]){
						for(f=0;f!=3;f++){
							r=t[f][i];
							t[f][i]=t[f][a];
							t[f][a]=r;
						}
					}
				}
			}
		}
		for(i=0;i!=n;i++){
			r=t[0][i];
			printf("%s\n",N[r]);
		}
		scanf("%d",&n);
	}
}

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

C++: 
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;


int main()
{
	int n; 
	while (cin >> n, n) {
		vector<pair<int, char>> v(n);

		for (int i = 0; i < n; i++) {
			cin >> v[i].second;
			int num = 0;
			for (int j = 0; j < n - 1; j++) {
				int x; cin >> x;
				if (x == 0)num += 100000;
				if (x == 1)num--;
			}
			v[i].first = num;
		}

		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());

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

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

int main(){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }

    char t[n];
    int win[n], lose[n];

    for(int i = 0; i < n; i++){
      cin >> t[i];

      win[i] = 0;
      lose[i] = 0;

      for(int j = 0; j < n - 1; j++){
        int x;
        cin >> x;

        if(x == 0) win[i]++;
        else if(x == 1) lose[i]++;
      }
    }

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

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

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

struct P{
    string team;
    int judge[30];
    int win,lose;
    static bool less(const P& left,const P& right){ return left.lose < right.lose; }
    static bool more(const P& le,const P& ri){ return le.win > ri.win; }
};

int main(){
    int n;
    P tmp;
    while(cin >> n,n){
        vector <P> data;
        for(int i=0;i<n;i++){
            tmp.win = 0;
            tmp.lose = 0;
            data.push_back(tmp);
        }
        for(int i=0;i<n;i++){
            cin >> data[i].team;
            for(int j=0;j<n-1;j++){
                cin >> data[i].judge[j];
                if(data[i].judge[j] == 1) data[i].lose++;
                else if(data[i].judge[j] == 0) data[i].win++;
            }
        }
        sort(data.begin(),data.end(),P::less);
        sort(data.begin(),data.end(),P::more);
        for(int i=0;i<n;i++) cout << data[i].team << endl;
    }
}