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<vector>
#include<string>
#include<map>
using namespace std;

int main()
{
	while (1) 
	{
		int a;
		cin >> a;
		if (a == 0)break;
		map<int, string>s;
		for (int p = 0; p < a; p++) {
			string b;
			cin>>b;
			int c = 0;
			for (int d = 0; d < a-1; d++) {
				int e;
				cin >> e;
				if (e == 0)c -= 100;
				else if (e == 2)c--;
			}
			cout << c << endl;
			s.insert(pair<int, string>(c, b));
		}
		for (auto q = s.begin(); q != s.end(); q++) {
			cout << q->second << endl;
		}
	}
}

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

typedef pair<char, int> pii;

bool fanc(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			char c;
			int num, sum = 0;
			cin >> c;
			
			for (int j = 0; j < n - 1; j++){
				cin >> num;
				sum += num != 2 ? num : 0;
				     //   ?????¶     ???   ???
			}
			
			p[i] = make_pair(c, sum);
		}
		
		sort(p.begin(), p.end(), fanc);
		
		for (int i = 0; i < n; i++){
			cout << p[i].first << endl;
		}
	}
	
	return (0);
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
#define MP make_pair
int main(){
	int n;
	for(;;){
		scanf("%d\n",&n);
		if(n==0) break;
		pair<pair<int,int>,pair<int,char> > ar[10];
		char c;
		int r;
		for(int i=0;i<n;i++){
			scanf("%c",&c);
			int win=0,lose=0;
			for(int j=0;j<n-1;j++){
				scanf(" %d",&r);
				if(r==0) win++;
				if(r==1) lose++;
			}
			ar[i]=MP(MP(-win,lose),MP(i,c));
			scanf("\n");
		}
		sort(ar,ar+n);
		for(int i=0;i<n;i++){
			printf("%c\n",ar[i].second.second);
		}
	}
}

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

bool cmp(pair<string,pair<int,int> > a, pair<string,pair<int,int> > b){
	a.second > b.second;
}

int main(){
	
	int n;
	int t;
	while(cin >> n && n){
		vector<pair<string,pair<int,int> > > team(n);
		
		for(int i=0;i<n;i++){
			cin >> team[i].first;
			for(int j=0;j<n-1;j++){
				cin >> t;
				if(t==0)team[i].second.first++;
				if(t==1)team[i].second.second--;
			}
		}
		stable_sort(team.begin(),team.end(),cmp);
		
		for(int i=0;i<team.size();i++){
			cout << team[i].first << endl;
		}
	}
}

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

C++: #include<bits/stdc++.h>
using namespace std;
int N;
string S[20];
int W[20];int L[20];
bool F[20];
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		for(int i=0;i<N;i++)F[i]=true;
		for(int i=0;i<N;i++){
			W[i]=0;L[i]=0;
		}
		for(int i=0;i<N;i++){
			cin >> S[i];
			for(int j=0;j<N-1;j++){
				int n;
				scanf("%d",&n);
				if(n==0)W[i]++;
				else if(n==1)L[i]++;
			}
		}
		for(int i=0;i<N;i++){
			int maxw=-1;int maxwi;bool FF=true;
			for(int j=0;j<N;j++){
				if(!F[j])continue;
				if(maxw<W[j]){
					
					maxw=W[j];maxwi=j;FF=true;
				}
				else if(maxw==W[j]){
					FF=false;
				}
			}
			if(FF){
				cout << S[maxwi] << "\n";
				F[maxwi]=false;
			}
			else{
				int minl=20;int minli;
				for(int j=0;j<N;j++){
					if(!F[j])continue;
					if(maxw!=W[j])continue;
					if(minl>L[j]){
						minl=L[j];
						minli=j;
					}
				}
				cout << S[minli] << "\n";
				F[minli]=false;
			}
		}
		
	}
}

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

int main(){
  int n;

  while(1) {
  cin >> n;
  if(n == 0) break;
  vector <int> v,lo;

  string str[10];
  v.resize(n);
  lo.resize(n);
  for(int i=0;i<n;i++) v[i] = lo[i] = 0;
  
  int a;
  for(int i=0;i<n;i++) {
    cin >> str[i];
    for(int j=0;j<n-1;j++) {
      cin >> a;
      if(a ==0) v[i]++;
      else if(a == 1) lo[i]++;
      
    }
  }
  
  string t;

  for(int i=0;i<n-1;i++) {
    for(int j=n-1;j>i;j--) {
      if(v[j] > v[j-1]) {
	t = str[j];
	str[j] = str[j-1];
	str[j-1]  = t;
	
	a = v[j];
	v[j] = v[j-1];
	v[j-1] = a;
	
	a = lo[j];
	lo[j] = lo[j-1];
	lo[j-1] = a;
	
      } else if(v[j] == v[j-1] && lo[j] < lo[j-1]) {
	t = str[j];
	str[j] = str[j-1];
	str[j-1] = t;

	a = lo[j];
	lo[j] = lo[j-1];
	lo[j-1] = a;
      }
    }
  }
      for(int i=0;i<n;i++) cout << str[i] << endl;

  } 


  return 0;
}

C++: #include<iostream>
using namespace std;
const int MAX=10;
int main(){
	char team[MAX+1];
	int n,score;
	int sum[MAX+1];
	while(cin >> n){
		if(n==0) break;
		for(int i=0; i<n; i++) sum[i]=0;
		
		for(int k=0; k<n; k++){
			cin >> team[k];
			for(int i=0; i<n-1; i++){
				cin >> score;
				if(score==0) sum[k]+=100;
				if(score==2) sum[k]+=1;
			}
			cout << team[k] << " " << sum[k] << endl;
		}
		int count=0;
		while(count!=n){
			int max_score=sum[0],winer=0;
			for(int i=0; i<n; i++){
				if(max_score < sum[i]){
					max_score = sum[i];
					winer=i;
				}
			}
			cout << team[winer] << endl;
			sum[winer]=-1;
			count++;
		}
	}
	return 0;
}

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

int main(){
  int n;

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

    pair<pair<int,int>,pair<int,char> > t[n];

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

      t[i].first.first = 0;
      t[i].first.second = 0;

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

        if(x == 0) t[i].first.first--;
        else if(x == 1) t[i].first.second++;
      }
    }

    sort(t, t + n);

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