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<utility>
#include<algorithm>
#include<queue>

using namespace std;

priority_queue<pair<pair<pair<int, int>,int>,char>> results;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		int win, lose;
		for (int i = 0; i < n;++i) {
			cin >> name;
			win = 0;lose = 0;
			for (int j = 0; j < n - 1; ++j) {
				int r;
				cin >> r;
				if (r == 2)continue;
				else if (r == 0)win++;
				else lose++;
			}results.emplace(make_pair(make_pair(make_pair(win,-lose),i),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*100000000+(make*-1);
			else 
				sum[i]=kati*100000000+(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 <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		pair<pair<int, int>, pair<int, char> > t[10];
		
		for (int i = 0; i < n; i++){
			t[i].first.first = t[i].first.second = 0;
			char name;
			scanf(" %c", &name);
			t[i].second.first = i;
			t[i].second.second = name;
			for (int j = 0; j < n - 1; j++){
				int x;
				scanf("%d", &x);
				if (x == 0) t[i].first.first--;
				if (x == 1) t[i].first.second++;
			}
		}
		
		sort(t, t + n);
		
		for (int i = 0; i < n; i++)
			printf("%c\n", t[i].second.second);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int main(){
  int n;
  while(cin>>n,n){
    string s[n];
    map<int,string>m;
    vector<pair<pair<int,int>,int> >a(n);
    for(int i=0;i<n;i++){
      cin>>s[i];
      m[i]=s[i];
      a[i].se=i;
      for(int j=0;j<n-1;j++){
        int p;
        cin>>p;
        if(!p)a[i].fi.se--;
        if(p==1)a[i].fi.fi++;
      }
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)swap(a[i].fi.se,a[i].fi.fi);
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)
      cout<<m[a[i].se]<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long int i,j,k,n,a,b,sum;
	int data;
	while(1) {
		cin>>n;
		vector<pair<int,char> > pp(n);
		
		if(n==0) break;
		for(i=0;i<n;i++) {
			cin>>pp[i].second;
			sum=0;
			for(j=0;j<n-1;j++) {
				cin>>a;
				if(a==0) sum+=100000;
				if(a==1) sum-=1;
			}
			pp[i].first=sum;
		}
		sort(pp.begin(),pp.end());
		for(i=n-1;i>=0;i--) {
			cout<<pp[i].second<<endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int i,j,k,n,sum[10];
	int data;
	char name[10][2];
	while(1) {
		cin>>n;
		if(n==0) 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]-=1;
			}
		}
		
		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]<<endl;
	}
	return 0;
}

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

struct PROFILE {
    char name[5];
    int score;
};

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

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].score = 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].score += (n - 1);
                else if (tmp == 1) team[i].score += -1;
            }
        }
        
        
        sort(team, team + n);
        
        for (int i = 0; i < n; i++){
            printf("%c\n", team[i].name[0]);
        }
    }
    
    return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	vector<pair<int,char> >ans;
	int n;
	while(cin>>n,n){
	vector<pair<int,char> >ans;
	for(int i=0;i<n;i++){
		char input;
		cin>>input;
		int rec=0;
		for(int j=0;j<n-1;j++){
			int k;
			cin>>k;
			if(k==0)rec+=10000;
			else if(k==1)rec-=100;
		}
		ans.push_back(make_pair(rec,input));
	}
	sort(ans.begin(),ans.end(),greater<pair<int,char> >());
	for(int i=0;i<n;i++){
		cout<<ans[i].second<<endl;
	}
}
}

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;

}