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 <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<pair<int, string>> v(n);
        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            int val = n-i;
            for (int j = 0; j < n-1; ++j) {
                int x;
                cin >> x;
                if(x == 0) val += 100000;
                if(x == 1) val -= 100;
            }
            v[i] = {val, s};
        }
        sort(v.begin(),v.end(), greater<>());
        for (int i = 0; i < n; ++i) {
            cout << v[i].second << "\n";
        }
    }
    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 = loset[i];
					loset[i] = loset[j];
					loset[j] = t;
					T = name[i];
					name[i] = name[j];
					name[j] = T;
				}
				else if(wint[i] == wint[j] && loset[i] > loset[j]){
					t = loset[i];
					loset[i] = loset[j];
					loset[j] = t;
					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<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main(){
  int n;
  while(cin >> n, n!=0){
    vector<pair<int, char>> v;

    for(int i=0; i<n; ++i){
      char tmp;
      cin >> tmp;
      v.push_back(make_pair(0, tmp));
      
      for(int j=0; j<n-1; ++j){
	int scr;
	cin >> scr;
	
	if(scr==0){
	  v[i].first = v[i].first + 10;
	}else if(scr==2){
	  v[i].first = v[i].first + 1;
	}
      }
      
    }
    sort(v.begin(), v.end(), greater<pair<int, char>>());
    for(auto i: v){
      cout << i.second << endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int n, i, t, r, j, temp;
    char str[11] = { 0 };
    char a[10] = { 0 };
    int b[10 + 1][10 + 1];
    int c[10 + 1];
    int d[10 + 1];
    int hideo[10 + 1];
    scanf("%d", &n);
    while (n > 0) {
        i = t = r = j = temp = 0;
        for (i = 1; i <= n; i++) {
            c[i] = 0;
            d[i] = 0;
            hideo[i] = 0;
            for (j = 1; j <= n; j++) {
                b[i][j] = 0;
            }
        }

        for (i = 1; i <= n; i++) {
            scanf("%s", &a[i]);
            str[i] = a[i];
            for (j = 1; j <= n - 1; j++) {
                scanf("%d", &b[i][j]);
                if (b[i][j] == 0) {
                    c[i]++;

                }
                if (b[i][j] == 1) {
                    d[i]++;
                }
            }
        }
        for (i = 1; i <= n; i++) {
            hideo[i] = c[i];
        }
        for (i = 1; i < n; i++) {
            for (j = n; j > i; j--) {
                if (c[j] > c[j - 1]) {
                    temp = c[j];
                    c[j] = c[j - 1];
                    c[j - 1] = temp;
                    a[1] = str[j];
                    str[j] = str[j - 1];
                    str[j - 1] = a[1];



                }
            }
        }
        for (i = 1; i <= n; i++) {
            if (c[i] == c[i + 1]) {
                if (d[i] > d[i + 1]) {
                    temp = c[i];
                    c[i] = c[i + 1];
                    c[i + 1] = temp;
                }
            }
        }
        for (i = 1; i <= n; i++) {
            printf("%c\n", str[i]);
        }
        scanf("%d", &n);
    }
}

C++: #include<stdio.h>
#include<algorithm>
struct Team{
	int input;
	int wins;
	int loses;
	char name;
};
Team t[10];
inline bool operator<(const Team &a,const Team &b){
	if(a.wins!=b.wins)return a.wins>b.wins;
	if(a.loses!=b.loses)return a.loses<b.loses;
	return a.input<b.input;
}
int main(){
	int n;
	while(1){
		scanf(" %d ",&n);
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			scanf(" %c ",&t[i].name);
			t[i].input=i;
			t[i].wins=0;
			t[i].loses=0;
			for(int j=0;j<n-1;j++){
				int val;
				scanf(" %d ",&val);
				if(val==0)t[i].wins++;
				else if(val==1)t[i].loses++;
			}
		}
		std::sort(t,t+n);
		for(int i=0;i<n;i++){
			printf("%c\n",t[i].name);
		}
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	char ti[10000];
	int ho[10000];
	while(1){
		int n,win[10000]={},lose[100000]={},blow[100000]={};
	
		cin >> n;
		if(n == 0) break;
		for(int i=0;i < n;i++){
			cin >> ti[i];
			for(int j=0;j<n-1;j++){
				cin >> ho[j];
				if(ho[j] == 0) win[i]+=1;
				if(ho[j] == 1) lose[i]+=1;
			}
		}for(int i=0;i<n;i++){
			for(int j=0;j+1<n;j++){
				if(win[j] < win[j+1] || (win[j]==win[j+1] && lose[j] > lose[j+1]) ){
					swap(lose[j],lose[j+1]);	
					swap(win[j],win[j+1]);	
					swap(ti[j],ti[j+1]);
				}
			}
		}for(int i=0;i<n;i++){
		 cout << ti[i] << endl;	
		}
	}
}