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<iostream>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;

int main(){

  int n;
  char c[11];
  int dat[11][11];
  typedef pair < int, pair < int, char > > P; //win, lose, name
  P team[11];

  while(cin >> n, n){

    for(int i=0;i<n;i++){
      cin >> team[i].S.S;
      for(int j=0;j<n-1;j++){
	cin >> dat[i][j];
	if(dat[i][j] == 1) team[i].S.F--;
	if(dat[i][j] == 0) team[i].F++;
      }
    }
    
    sort(team, team+n);
    reverse(team, team+n);

    for(int i=0;i<n;i++) cout << team[i].S.S << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>

typedef struct{
	char name[100];
	int win;
	int lose;
	int prior;
}team;

void swap(team *p, team *q){
	team tmp = *p;
	*p = *q;
	*q = tmp;
}

int main(){
	while(1){
		int n, a;
		char c[100];
		team t[10];
		
		scanf(" %d", &n);
		if(n==0) break;
	
		for(int i=0; i<n; i++){
			scanf(" %s", c);
			strcpy(t[i].name, c);
			t[i].win=0;
			t[i].lose=0;
			t[i].prior=i;
			
			for(int j=0; j<n-1; j++){
				scanf(" %d", &a);
				if(a==0) ++t[i].win; 
				else if(a==1) ++t[i].lose;
			}
		}
		
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if( (t[i].win > t[j].win) || (t[i].win==t[j].win && t[i].lose < t[j].lose) ||  (t[i].win==t[j].win && t[i].lose==t[j].lose && t[i].prior < t[j].prior) )
					swap(&t[i], &t[j]);
			}
		}
	
		for(int i=0; i<n; i++)
			printf("%s\n", t[i].name);

	}

	return 0;
}

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

struct PROFILE {
    char name[5];
    int win_num;
    int lose_num;
};

bool operator<(const PROFILE& left, const PROFILE& right)
{
    return left.win_num > right.win_num;
}

int main(void)
{
    struct PROFILE team[10];
    int n;
    
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < 10; i++){
           team[i].win_num = team[i].lose_num = 0;
        }
        
        int tmp;
        for (int i = 0; i < n; i++){
            scanf("%s", team[i].name);
            for (int j = 0; j < (n - 1); j++){
                scanf("%d", &tmp);
                if (tmp == 0) team[i].win_num++;
                else if (tmp == 1) team[i].lose_num++;
            }
        }
        
        sort(team, team + n);
        
        for (int i = 0; i < n; i++){
            printf("%c\n", team[i].name[0]);
        }
    }
    
    return (0);
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(void){

	int n;
	char t[10];
	int r;
	int win[10] = { 0 }, lose[10] = { 0 };
	memset(win, 0, sizeof(win)); memset(lose, 0, sizeof(lose));

	while (cin >> n && n != 0){

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

		bool flg = true;
		int i = 0;
		while (flg){
			flg = false;
			for (int j = n - 1; j >= i + 1; j--){
				if (win[j] > win[j - 1]){
					swap(win[j], win[j - 1]); swap(lose[j], lose[j - 1]); swap(t[j], t[j - 1]);
					flg = true;
				}
				else if (win[j] == win[j - 1]){
					if (lose[j] < lose[j - 1]){
						swap(win[j], win[j - 1]); swap(lose[j], lose[j - 1]); swap(t[j], t[j - 1]);
						flg = true;
					}
				}
			}
			i++;
		}
		for (i = 0; i < n;i++){
			cout << t[i] << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  for(int n; cin >> n && n;) {
    vector<pair<pair<int,int>,pair<int,char> > > v;
    for(int i = 0; i < n; ++i) {
      char t;
      cin >> t;
      int a = 0, b = 0;
      for(int j = 0; j < n-1; ++j) {
        int r;
        cin >> r;
        if(r == 0) ++a;
        else if(r == 1) ++b;
      }
      v.push_back(make_pair(make_pair(-a, b), make_pair(i, t)));
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size(); ++i) {
      cout << v[i].second.second << endl;
    }
  }
  return 0;
}

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

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		pair<int, char> scores[10];
		for (int i = 0; i < n; ++i)
		{
			char name;
			scanf(" %c", &name);
			int w, l;
			w = l = 0;
			for (int j = 1; j < n; ++j)
			{
				int t;
				scanf("%d", &t);
				if (t == 0)
					++w;
				else if (t == 1)
					++l;
			}
			scores[i] = make_pair(w*1000 - l, name);
		}
		sort(scores, scores+n, greater<pair<int, char> >());
		for (int i = 0; i < n; ++i)
			printf("%c\n", scores[i].second);
	}

	return 0;
}