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>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    char t[n];
    char kt;
    int tt[2][n];
    int k;
    int h;
    for(int i=0;i<2;i++){
      for(int j=0;j<n;j++){
	tt[i][j] = 0;
      }
    }
    for(int i=0;i<n;i++){
      cin >> t[i];
      for(int j=0;j<n-1;j++){
	cin >> h;
	if(h==0) tt[0][i] += 1;
	if(h==1) tt[1][i] += 1;
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(tt[0][j]>=tt[0][j+1]){
	  k = tt[0][j];
	  tt[0][j] = tt[0][j+1];
	  tt[0][j+1] = k;
	  k = tt[1][j];
	  tt[1][j] = tt[1][j+1];
	  tt[1][j+1] = k;
	  kt = t[j];
	  t[j] = t[j+1];
	  t[j+1] = kt;
	}
	else if(tt[0][j]==tt[0][j+1]&&tt[1][j]<=tt[1][j+1]){
    	  k = tt[0][j];
	  tt[0][j] = tt[0][j+1];
	  tt[0][j+1] = k;
	  k = tt[1][j];
	  tt[1][j] = tt[1][j+1];
	  tt[1][j+1] = k;
	  kt = t[j];
	  t[j] = t[j+1];
	  t[j+1] = kt;
	}
      }
    }
    for(int i=n-1;i>=0;i--) cout << t[i] << endl;
  }
  return 0;
}

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

struct Team {
	char name;
	int wins;
	int loss;
};
bool operator > (const Team& t1, const Team& t2) {
	if (t1.wins > t2.wins) return true;
	else if (t1.wins < t2.wins) return false;
	else return t1.loss < t2.loss;
}

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n == 0) break;
		Team* teams = new Team[n];
		for (int i=0; i<n; i++) {
			char c; std::cin >> c;
			teams[i].name = c;
			int wins = 0;
			int loss = 0;
			for (int j=0; j<n-1; j++) {
				int x; std::cin >> x;
				if (x==0) wins++;
				else if (x==1) loss++;
			}
			teams[i].wins = wins;
			teams[i].loss = loss;
		}
		std::sort(teams, teams + n, std::greater<Team>());
		for (int i=0; i<n; i++) std::cout << teams[i].name << std::endl;
		delete[] teams;
	}
	return 0;
}

C++: // Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		char T[10];
		int W[10], L[10], I[10];

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

			W[i] = L[i] = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;

				if(r==0){
					W[i]++;
				}
				else if(r==1){
					L[i]++;
				}
			}

			I[i] = i;
		}

		for(int i=0; i<n-1; i++){
			for(int 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]&&I[i]>I[j])){
					char c_tmp = T[i];
					T[i] = T[j];
					T[j] = c_tmp;

					int tmp = W[i];
					W[i] = W[j];
					W[j] = tmp;

					tmp = L[i];
					L[i] = L[j];
					L[j] = tmp;

					tmp = I[i];
					I[i] = I[j];
					I[j] = tmp;
				}
			}
		}

		for(int i=0; i<n; i++){
			cout << T[i] << '\n';
		}
	}

	return 0;
}

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

using namespace std;

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

    if(n == 0){
      break;
    }

    vector<pair<int,char>> total_result;
    int result;

    for(int i = 0;i < n;++i){
      int point = 0;
      char name;
      cin>>name;

      for(int j = 0;j < n - 1;++j){
        cin>>result;
        if(result == 0){
          point -= 100;
        }
        else if(result == 2){
          point -= 1;
        }
      }

      total_result.push_back(make_pair(point,name));
    }

    sort(total_result.begin(),total_result.end());

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,sum[11];
	int data;
	char name[11][11];
	while(1) {
		cin>>n;
		if(!n) break;
		for(i=0;i<n;i++) sum[i]=0;
		for(i=0;i<n;i++) {
			cin>>name[i];
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) sum[i]+=10000;
				else if(data==1) sum[i]--;
			}
		}
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				if(sum[i]<sum[j]) {
					swap(sum[i],sum[j]);
					swap(name[i],name[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<name[i]<<sum[i]<<endl;
	}
	return 0;
}

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

using namespace std;
int i,j,make[100],kati[100];
char name[100];

void change(){
  int tmp1,tmp2;
  char tmp3;
  tmp1 = kati[j+1];
  kati[j+1] = kati[j];
  kati[j] = tmp1;
  
  tmp2 = make[j+1];
  make[j+1] = make[j];
  make[j] = tmp2;
  
  tmp3 = name[j+1];
  name[j+1] = name[j];
  name[j] = tmp3;
}

int main(){
  int n,s;
  while(1){
    cin >> n;
    if( n == 0 )break;
    for( i = 0;i < 100 ; i++){
      kati[i] = 0;
      make[i] = 0;
    }
    
    for( i = 0 ; i < n ; i++ ){
	cin >> name[i];
      for( j = 0; j < n-1 ; j++ ){
	cin >> s;
	if(s == 0)kati[i]++;
	if(s == 1)make[i]++;
      }
    }

    
    
    for( i = n-1;i >0 ; i--){
      for( j = 0; j < i ; j++){
	if(make[j] < make[j+1] ){
	  change();
	}
      }
    }
    
    for( i = n-1;i >0 ; i--){
      for( j = 0; j < i ; j++){
	if(kati[j] < kati[j+1] ){
	  change();
	}
      }
    }

    for(i = 0;i < n ;i++)cout << name[i] << endl;
    
  }
  return 0;
}

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

using namespace std;
int i,j,make[100],kati[100];
char name[100];

void change(){
  int tmp1,tmp2;
  char tmp3;
  tmp1 = kati[i];
  kati[i] = kati[j];
  kati[j] = tmp1;
  
  tmp2 = make[i];
  make[i] = make[j];
  make[j] = tmp2;
  
  tmp3 = name[i];
  name[i] = name[j];
  name[j] = tmp3;
}

int main(){
  int n,s;
  while(1){
    cin >> n;
    if( n == 0 )break;
    for( i = 0;i < n ; i++){
      kati[i] = 0;
      make[i] = 0;
    }
    
    for( i = 0 ; i < n ; i++ ){
	cin >> name[i];
      for( j = 0; j < n-1 ; j++ ){
	cin >> s;
	if(s == 0)kati[i]++;
	if(s == 1)make[i]++;
      }
    }

    for( i = 0; i < n-1 ; i++){
      for( j = i+1; j < n ; j++){
	if(kati[i] < kati[j] ){
	  change();
      }
      }
    }
    //     for(i = 0;i < n ;i++)cout << name[i] << endl;

         for( i = 0; i < n ; i++){
      for( j = i+1; j < n ; j++){

	if(( kati[i]==kati[j] )&&( make[i] > make[j] )){
	    change();
	  }
      }
      }
    
     for(i = 0;i < n ;i++)cout << name[i] << endl;
    
  }
  return 0;
}