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 <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  while (cin >> n, n){
    pair<pair<int, int>, char> ppiic[11];
    for (int i = 0; i < n; i++){
      char c;
      ppiic[i].first = make_pair(0, 0);
      cin >> c;
      ppiic[i].second = c;
      for (int j = 0; j < n - 1; j++){
        int num;
        cin >> num;
        if (num == 0) ppiic[i].first.first++;
        else if (num == 1) ppiic[i].first.second--;;
      }
    }
    stable_sort(ppiic, ppiic + n);
    reverse(ppiic, ppiic + n);

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

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

void ins(vector< pair<int,pair<int,char> > > &a){
    int s = a.size() - 1;
    if(s == 0) return ;
    while(a[s].first > a[s-1].first){
	swap(a[s],a[s-1]);
	s--;
	if(s==0) break;
    }
    if(s ==0) return;
    while(a[s].first == a[s-1].first && a[s].second.first < a[s-1].second.first){
	swap(a[s],a[s-1]);
	s--;
	if(s==0) break;
    }
    return ;
}

int main(){
    while(true){
	int n;
	cin >> n;
	vector< pair<int,pair<int,char> > > ans;
	if(n == 0) break;
	REP(i,n){
	    char t;
	    int temp;
	    int w,l;
	    w =0 ;
	    l = 0;
	    cin >> t;
	    REP(i,n-1) {
		cin >> temp;
		if(temp == 0) w++;
		else if( temp == 1) l++;
	    }
	    ans.PB( pair<int,pair<int,char> >( w , pair<int,char>(l,t) ));
	    ins(ans);
	}
	REP(i,n) cout << ans[i].second.second << 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;i++){
			for(j=0;j<a;j++){
				if(i!=j){
					if(d[i]>d[j]){
						g=d[i];
						d[i]=d[j];
						d[j]=g;
						h=f[i];
						f[i]=f[j];
						f[j]=h;
						strcpy(x,z[i]);
						strcpy(z[i],z[j]);
						strcpy(z[j],x);
					}
					else if(d[i]==d[j]){
						if(f[i]<f[j]){
							g=d[i];
							d[i]=d[j];
							d[j]=g;
							h=f[i];
							f[i]=f[j];
							f[j]=h;
							strcpy(x,z[i]);
							strcpy(z[i],z[j]);
							strcpy(z[j],x);
						}
					}
				}
			}
		}
		for(i=0;i<a;i++) printf("%s\n",z[i]);
	}
	return 0;
}

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

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		double w, f;
		priority_queue<pair<double,char>> results;
		for (int i = 0; i < n;++i) {
			cin >> name;
			w = 0.0, f = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				double r;
				cin >> r;
				if (r == 0)++w;
				if (r == 1)++f;
			}
			f *= 0.00000000000001;
			double result = w - f;
			results.push(make_pair(result,name));
		}
		while(!results.empty()) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	char name[10];
	long long int toku[9][5],n,make,kati,hiki,sum[9],touroku[9];
	int flg[9];
	while(1) {
		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>>toku[i][j];
			}
		}
		for(int i=0;i<n;i++) {sum[i]=0;touroku[i]=0;}
		for(int i=0;i<n;i++) {
			kati=0;make=0;
			for(int j=0;j<n-1;j++) {
				if(toku[i][j]==0) kati++;
				if(toku[i][j]==1) make++;
			}	
			if(kati>0)
				sum[i]=kati*1000000000+(make*-1);
			else 
				sum[i]=kati*1000000000+(make*-1);
		/*	else if(kati==0 && make>0) 
				sum[i]=kati*10000000*-1+(make*-1);*/
		//	cout<<sum[i]<<" "<<name[i]<<endl;
		}
		for(int i=0;i<n;i++) touroku[i]=sum[i];
		sort(sum,sum+n,greater<int>());
	//	for(int i=0;i<n;i++) cout<<sum[i]<<endl;;
		for(int i=0;i<n;i++) flg[i]=0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(sum[i]==touroku[j] && flg[j]==0) {
					cout<<name[j]<<endl;
					flg[j]=1;
					break;
				}
			}
		}
	}
}

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

using namespace std;

int result[5];

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	int n;
	while(cin>>n,n){
		vector<char> tn(n);
		vector<int> point(n);
		int max = 0;
		rep(i,n){
			cin>>tn[i];
			int data;
			rep(j,n-1){
				cin>>data;
				if(data==0)point[i]+=3;
				if(data==1)point[i]+=0;
				if(data==2)point[i]+=1;
			}
		if(max<point[i])max = point[i];
		}
		for(int i = max ; 0 <= i ; i --){
			rep(j,n)
			if(i==point[j])cout<<tn[j]<<endl;
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(void){
	int n;
	while(cin>>n,n){
		multimap<int,string,greater<int> > ranking;
		for(int i=0;i<n;++i){
			string s;
			int win=0,lose=0;
			cin>>s;
			for(int j=0,score;j<n-1;++j){
				cin>>score;
				if(score==0) win++;
				else if(score==1) lose++;
			}
			ranking.insert(multimap<int,string>::value_type(win+n-lose,s));
		}
		multimap<int,string,greater<int> >::iterator it;
		for(it=ranking.begin();it!=ranking.end();++it){
			cout<<(*it).second<<endl;
		}
	}
	return 0;
}

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

int main(){
  pair<int,char> game[10];
  int team,point[10][10],ten[10]={0};
  
  while(1){
    cin >> team;
    if(team == 0)break;

    for(int i=0;i<team;i++){
      cin >> game[i].second;
      for(int j=0;j<team-1;j++){
	cin >> point[i][j];
	if(point[i][j] == 0){
	  ten[i] += 2;
	}
	else if(point[i][j] == 2){
	  ten[i]++;
	}
      }
      game[i].first = ten[i];
    }
    sort(game,game+team);

    for(int i=team-1;0<=i;i--){
      cout << game[i].second << endl;
    }
  }
  return 0;
}