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

struct Team {

	char name;
	int  winCnt;
	int  loseCnt;

};

int main()
{

	int n, r;
	Team t[10];

	while( cin >> n, n ) {

		for( int i = 0; i < 10; i++ ) { t[i].winCnt = 0; t[i].loseCnt = 0; }

		for( int i = 0; i < n; i++ ) {
			cin >> t[i].name;
			for( int j = 0; j < n - 1; j++ ) {

				cin >> r;
				if( r == 0 ) t[i].winCnt++;
				else if( r == 1 ) t[i].loseCnt++;

			}
		}

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

				Team temp;

				if( t[i].winCnt == t[j].winCnt ) {
					if( t[i].loseCnt > t[j].loseCnt ) {

						temp = t[i];
						t[i] = t[j];
						t[j] = temp;

					}
				}
				else if( t[i].winCnt < t[j].winCnt ) {

					temp = t[i];
					t[i] = t[j];
					t[j] = temp;

				}

			}
		}

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

	}

	return 0;

}

C++: #include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    vector<pair<pair<int,int>, char> > team;
    map<int,char> team_n;
    char c;
    int x;
    for(int i=0; i<n; i++){
      cin >>c;
      team_n[-i] = c;
      team.push_back(make_pair(make_pair(0,0),-i));
      for(int j=0; j<n-1; j++){
	cin >>x;
	if(x == 0){team[i].first.first++;}
	if(x == 1){team[i].first.second--;}
      }
    }
    sort(team.begin(),team.end());
    for(int i=team.size()-1; i>=0; i--){
      cout <<team_n[team[i].second]<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
int a[100000];
int n, sum, p;
char c[100000];
int main() {
	while (true) {
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> c[i];
			sum = 0;
			for (int j = 0; j < n - 1; j++) {
				cin >> p;
				if (p == 0) { sum += 10000; }
				if (p == 2) { sum += 100; }
				sum += (20 - i);
			}
			a[i] = sum;
		}
		sort(a, a + n);
		for (int i = n - 1; i >= 0; i--) {
			cout << c[20 - (a[i] % 100)] << endl;
		}
	}
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,ii,jj,n,rr[10][3],r,temp,flg;
	char t[11],ctm,tcopy[11];
	while(1){
		cin>>n;
		if(n==0)break;
		for(i=0;i<n;i++){
			cin>>t[i];
			tcopy[i]=t[i];
			rr[i][0]=0; rr[i][1]=0; rr[i][2]=0;
			for(j=0;j<n-1;j++){
				cin>>r;
				rr[i][r]++;
			}
		}
//		for(i=0;i<n;i++)printf("%c ??????%d?????????%d\n",t[i],rr[i][0],rr[i][1]);
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][0]<rr[j][0]){
					temp=rr[i][0];
					rr[i][0]=rr[j][0];
					rr[j][0]=temp;
					
					temp=rr[i][1];
					rr[i][1]=rr[j][1];
					rr[j][1]=temp;
					
					ctm=t[i];
					t[i]=t[j];
					t[j]=ctm;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][1]>rr[j][1]&&rr[i][0]==rr[j][0]){
					temp=rr[i][0];
					rr[i][0]=rr[j][0];
					rr[j][0]=temp;
					
					temp=rr[i][1];
					rr[i][1]=rr[j][1];
					rr[j][1]=temp;
					
					ctm=t[i];
					t[i]=t[j];
					t[j]=ctm;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(rr[i][1]==rr[j][1]&&rr[i][0]==rr[j][0]){
					flg=0;
					for(k=0;k<n;k++){
						if(t[i]==tcopy[k])flg=1;
						if(t[j]==tcopy[k]&&flg==0){
							temp=rr[i][0];
							rr[i][0]=rr[j][0];
							rr[j][0]=temp;
							
							temp=rr[i][1];
							rr[i][1]=rr[j][1];
							rr[j][1]=temp;
							
							ctm=t[i];
							t[i]=t[j];
							t[j]=ctm;
							break;
						}
					}
				}
			}
		}
		for(i=0;i<n;i++) cout<<t[i]<<endl;
	}
	return 0;
}

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>
using namespace std;
int main()
{
	int n,r,wint[10],loset[10],t;
	char name[11],T;
	while(1){
		for(int i=0;i<10;i++){
			wint[i]=0;
			loset[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 >> r;
				if(r==0)
					wint[i]++;
				else if(r==1)
					loset[i]++;
			}
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(wint[i] < wint[j]){
					t = wint[i];
					wint[i] = wint[j];
					wint[j] = t;
					T = name[i];
					name[i] = name[j];
					name[j] = T;
				}
				else if(wint[i] == wint[j] && loset[i] > loset[j]){
					T = name[i];
					name[i] = name[j];
					name[j] = T;
				}
			}
		}
		for(int i=0;i<n;i++){
			cout << name[i] << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[11],f[11],g,h,i,j;
	char z[11][11],x[11];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			d[i]=0;
			f[i]=0;
			scanf("%s",z[i]);
			for(j=0;j<a-1;j++){
				scanf("%d",&s);
				if(s==0) d[i]++;
				if(s==1) f[i]++;
			}
		}
		for(i=0;i<a-1;i++){
			for(j=i+1;j<a;j++){
				if(d[i]<d[j]){
					g=d[i];
					d[i]=d[j];
					d[j]=g;
					g=f[i];
					f[i]=f[j];
					f[j]=g;
					strcpy(x,z[i]);
					strcpy(z[i],z[j]);
					strcpy(z[j],x);
				}
				if(d[i]==d[j]){
					if(f[i]>f[j]){
						g=d[i];
						d[i]=d[j];
						d[j]=g;
						g=f[i];
						f[i]=f[j];
						f[j]=g;
						strcpy(x,z[i]);
						strcpy(z[i],z[j]);
						strcpy(z[j],x);
					}
				}
			}
		}
		for(i=0;i<a;i++){
				printf("%c\n",z[i][0]);
		}
	}
	return 0;
}