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>
#include <tuple>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    vector<tuple<char, int, int>> teams;
    while(cin >> n && n){
        teams.resize(n);
        for(int i = 0; i < n; i++){
            char team;
            cin >> team;
            int win = 0, lose = 0;
            for(int j = 0; j < n - 1; j++){
                int result;
                cin >> result;
                switch(result){
                case 0:
                    win++;
                case 1:
                    lose++;
                }
            }
            teams[i] = make_tuple(team, win, lose);
        }
        sort(begin(teams), end(teams), [](tuple<char, int, int> a, tuple<char, int, int> b){
            if(get<1>(a) != get<1>(b)){
                return get<1>(a) > get<1>(b);
            }else{
                return get<2>(a) < get<2>(b);
            }
        });
        for(auto&& i : teams){
            cout << get<0>(i) << "\n";
        }
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(void){

	int n;
	char t[10];
	int r;
	int win[10] = { 0 }, lose[10] = { 0 };

	while (cin >> n && n != 0){

		for (int i = 0; i < n; i++){
			cin >> t[i];
			for (int j = 0; j < n - 1; j++){
				cin >> r;
				if (r == 0) win[i]++;
				if (r == 1) lose[i]++;
			}
		}

		/*for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				if (win[i] < win[j]){
					swap(win[i], win[j]);
					swap(lose[i], lose[j]);
					swap(t[i], t[j]);
				}
				else if (win[i] == win[j]){
					if (lose[i] > lose[j]){
						swap(win[i], win[j]);
						swap(lose[i], lose[j]);
						swap(t[i], t[j]);
					}
				}
			}*/
		bool flg = true;
		int i = 0;
		while (flg){
			flg = false;
			for (int j = n - 1; j >= i + 1; j--){
				if (win[j] > win[j - 1]){
					swap(win[j], win[j - 1]); swap(lose[j], lose[j - 1]); swap(t[j], t[j - 1]);
					flg = true;
				}
				else if (win[j] == win[j - 1]){
					if (lose[j] < lose[j - 1]){
						swap(win[j], win[j - 1]); swap(lose[j], lose[j - 1]); swap(t[j], t[j - 1]);
						flg = true;
					}
				}
			}
			i++;
		}
		for (i = 0; i < n;i++){
			cout << t[i] << endl;
		}
	}
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

struct Team{
	char name[2];
	int win,lose;
};

int main(){

	int n,tmp;
	Team team[10];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0;i < n; i++){
			team[i].win = 0;
			team[i].lose = 0;
		}

		for(int i = 0; i < n; i++){
			scanf("%s",team[i].name);

			for(int k = 0; k < n-1; k++){
				scanf("%d",&tmp);
				if(tmp == 0)team[i].win++;
				else if(tmp == 1)team[i].lose++;
			}
		}

		for(int i=1; i <= n-1; i++){
			for(int k=n-1; k >= i; k--){
				if(team[k].win > team[k-1].win)swap(team[k],team[k-1]);
				else if(team[k].win == team[k-1].win && team[k].lose < team[k-1].lose)swap(team[k],team[k-1]);
			}
		}

		for(int i = 0; i < n; i++){
			printf("%s\n",team[i].name);
		}

	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	int team[10][3],n,i,j,k,c;
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		
		memset(team,0,sizeof(team));
		
		for(i=0;i<n;i++){
			scanf(" %c ",&team[i][0]);
			for(j=0;j<n-1;j++){
				scanf("%d",&c);
				if(c==0)++team[i][1];
				if(c==1)++team[i][2];
			}
		}
		
		for(i=0;i<n;i++){
			for(j=0;j<n-1;j++){
				if(team[j][2]>team[j+1][2]){
					for(k=0;k<3;k++){
						c=team[j][k];
						team[j][k]=team[j+1][k];
						team[j+1][k]=c;
					}
				}
			}
		}
		
		for(i=0;i<n;i++){
			for(j=0;j<n-1;j++){
				if(team[j][1]<team[j+1][1]){
					for(k=0;k<3;k++){
						c=team[j][k];
						team[j][k]=team[j+1][k];
						team[j+1][k]=c;
					}
				}
			}
		}

		for(i=0;i<n;i++){
			printf("%c\n",team[i][0]);
		}
	}
	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];
  
  while(1){
    for(int i=0;i<10;i++){
      ten[i] = 0;
    }
    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;
}

C++: #include<iostream>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  while(true){
    int n,a;
    cin>>n;
    if(!n)break;
    char name[n];
    int score;
    multimap<int, int> teams;
    for(int i=0;i<n;i++){
      cin>>name[i];
      score = 0;
      for(int j=0;j<n-1;j++){
	cin>>a;
	if(a==0)score-=100;
	if(a==1)score++;	
      }
      teams.insert(mp(score,i));
    }
    map<int, int>::iterator it = teams.begin();
    while( it != teams.end() ){
      cout << name[(*it).second] << endl;
      it++;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  while (cin >> n, n){
    pair<pair<int, int>, pair<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 = make_pair(i, 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++;
      }
    }
    sort(ppiic, ppiic + n);

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