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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        vi v(7,0);
        rep(i,n){
            int gotiusa_is_a_god_especially_tiya;
            cin>>gotiusa_is_a_god_especially_tiya;
            if(gotiusa_is_a_god_especially_tiya>=60)gotiusa_is_a_god_especially_tiya=60;
            v[gotiusa_is_a_god_especially_tiya/10]++;
        }
        rep(i,7)cout<<v[i]<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct team {
  string name;
  int win;
  int lose;
};

class winner {
public:
  bool operator() (const team& a, const team& b) {
    if(a.win != b.win) {
    return a.win > b.win;
    }
    else {
      return a.lose > b.lose;
    }
  }
};

vector<team> T;

int main() {
  int n,res;
  while(cin >> n) {
    if(n==0) break;
    for(int i=0;i<n;i++) {
      team temp;
      temp.win = 0;temp.lose = 0;
      cin >> temp.name;
      for(int j=0;j<n-1;j++) {
        cin >> res;
        if(res == 0) temp.win++;
        if(res == 1) temp.lose--;
        if(res == 2) continue;
      }
      //      cout << temp.name << " " << temp.win << " " << temp.lose << endl;
      T.push_back(temp);
    }

    sort(T.begin(),T.end(), winner());
    for(int i=0;i<n;i++) {
      cout << T[i].name << endl;
      }
    T.clear();
  }
}

C++: #include<stdio.h>
int main(void)
{
	int n,p[100];
	int i,j,temp;
	int w[100],l[100],a[100];
	char t[100],m;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			w[i]=0;
			l[i]=0;
			scanf(" %c",&t[i]);
			a[i]=i;
			for(j=0;j<n-1;j++){
				scanf("%d",&p[j]);
				if(p[j]==0){
					w[i]++;
				}
				if(p[j]==1){
					l[i]++;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(w[i]<w[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && l[i]<l[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j] && a[i]>a[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;				
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%c\n",t[i]);
		}
		scanf("%d",&n);
	}
	return 0;
}

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

int main(){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }

    char t[n];
    int id[n], win[n], lose[n];

    for(int i = 0; i < n; i++){
      id[i] = i;
      cin >> t[i];

      win[i] = 0;
      lose[i] = 0;

      for(int j = 0; j < n - 1; j++){
        int x;
        cin >> x;

        if(x == 0) win[i]++;
        else if(x == 1) lose[i]++;
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        if(win[i] < win[j] ||
           win[i] == win[j] && lose[i] > lose[j] ||
           win[i] == win[j] && lose[i] == lose[j] && id[i] > id[j]){
          swap(id[i], id[j]);
          swap(t[i], t[j]);
          swap(win[i], win[j]);
          swap(lose[i], lose[j]);
        }
      }
    }

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

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

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

		char t[10];
		int r;
		int win[10] = { 0 }, lose[10] = { 0 };
		memset(win, 0, sizeof(win)); memset(lose, 0, sizeof(lose));

		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]++;
			}
		}

		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>
int main(void)
{
	int i,j,n,r,x[100],w;
	char t[100],q[10];
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf(" %c ",&t[i]);
			x[i]=0;
			for(j=0;j<n-1;j++){
				scanf("%d",&r);
				if(r==0) x[i]+=10;
				else if(r==2) x[i]++;
			}
		}
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){
				if(x[i]<x[j]){
					w=x[i];
					x[i]=x[j];
					x[j]=w;
					q[0]=t[i];
					t[i]=t[j];
					t[j]=q[0];
				}
			}
		}
		for(i=0;i<n;i++) printf("%c %d\n",t[i],x[i]);
	}
	return 0;
}