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

int main() {
  int n;
  
  while(cin >> n, n) {
    vector<vector<int> > G(n, vector<int>(n-1, 0));
    vector<int> win(n), lose(n);
    vector<pair<int, string> > team(n);
    
    for(int i=0; i<n; i++) {
      team[i].first = i;
      cin >> team[i].second;
      for(int j=0; j<n-1; j++) {
	cin >> G[i][j];
	win[i]  += G[i][j] == 0;
	lose[i] += G[i][j] == 1;
      }
    }
    
    for(int i=0; i<n-1; i++) {
      for(int j=i+1; j<n; j++) {
	if(win[i] == win[j]) {
	  if(lose[i] == lose[j]
	     && team[i].first > team[j].first) {
	    swap(win[i], win[j]);
	    swap(lose[i], lose[j]);
	    swap(team[i], team[j]);
	  }
	  else if(lose[i] > lose[j]) {
	    swap(win[i], win[j]);
	    swap(lose[i], lose[j]);
	    swap(team[i], team[j]);
	  }
	} else if(win[i] < win[j]){
	  swap(win[i], win[j]);
	  swap(lose[i], lose[j]);
	  swap(team[i], team[j]);
	}
      }
    }
    for(int i=0; i<n; i++) cout << team[i].second << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
struct base{
	char team;
	int win;
	int lose;
};

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		struct base champ[10];
		for(int i=0;i<n;i++){
			champ[i].win = 0;
			champ[i].lose = 0;
		}
		for(int i=0;i<n;i++){
			cin>>champ[i].team;
			for(int j=0;j<n-1;j++){
				int a;
				cin>>a;
				if(a==0) champ[i].win++;
				else if(a==1) champ[i].lose++;
			}
		}
		struct base temp;
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(champ[i].win < champ[j].win){
					temp = champ[i];
					champ[i] = champ[j];
					champ[j] = temp;
				}else if(champ[i].win == champ[j].win){
					if(champ[i].lose > champ[j].lose){
						temp = champ[i];
						champ[i] = champ[j];
						champ[j] = temp;
					}
				}
			}
		}

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

	return 0;
}

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

struct data{
    char name;
    int win, lose;
    data(char n, int w, int l) : name(n), win(w), lose(l) {}
    bool operator<(const data other) const{
        if(win != other.win)    return win < other.win;
        else                    return lose > other.lose;
    }
};

int main(){
    while(1){
        int n;
        cin >> n;

        if(n == 0)  break;

        vector<data> result;
        char t;
        int r;

        for(int i = 0; i < n; i++){
            cin >> t;
            int w = 0, l = 0;
            for(int j = 0; j < n-1; j++){
                cin >> r;
                if(r == 0)  w++;
                if(r == 1)  l++;
            }
            result.push_back(data(t, w, l));
        }

        sort(result.rbegin(), result.rend());

        for(data d : result)    cout << d.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+=100;
				else if(r==1) --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<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j,r,rr[10][3];
string s,t[10];
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)rr[i][0]=rr[i][1]=rr[i][2]=0;
for(i=0;i<n;i++){
cin>>t[i];
for(j=0;j<n-1;j++){cin>>r;rr[i][r]++;}
}
for(i=0;i<n-1;i++){
for(j=n-1;j>i;j--){
if(rr[j-1][0]<rr[j][0]||rr[j-1][0]==rr[j][0]&&rr[j-1][1]>rr[j][1]){
s=t[j-1];t[j-1]=t[j];t[j]=s;
r=rr[j-1][0];rr[j-1][0]=rr[j][0];rr[j][0]=r;
r=rr[j-1][1];rr[j-1][1]=rr[j][1];rr[j][1]=r;
r=rr[j-1][2];rr[j-1][2]=rr[j][2];rr[j][2]=r;
}
}
}
for(i=0;i<n;i++)cout<<t[i]<<endl;
}
return 0;
}

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