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>
using namespace std;
int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)
			break;
		
		vector<char> t(n);
		vector<int> win(n), lose(n), drow(n);
		vector<int> num(n);
		for (int i = 0; i < n; i++)
			num.at(i) = i;

		int score;
		for (int i = 0; i < n; i++) {
			cin >> t.at(i);
			for (int j = 0; j < n - 1; j++) {
				cin >> score;
				switch (score) {
				case(0):win.at(i)++;
				case(1):lose.at(i)++;
				case(2):drow.at(i)++;
				}
			}
		}

		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (win.at(num.at(i)) < win.at(num.at(j))) {
					swap(num.at(i), num.at(j));
				}
			}
		}
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (win.at(num.at(i)) == win.at(num.at(j)) && lose.at(num.at(i)) > lose.at(num.at(j))) {
					swap(num.at(i), num.at(j));
				}
			}
		}
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (win.at(num.at(i)) == win.at(num.at(j)) && lose.at(num.at(i)) == lose.at(num.at(j)) && num.at(i) > num.at(j)) {
					swap(num.at(i), num.at(j));
				}
			}
		}

		for (int i = 0; i < n; i++)
			cout << t.at(num.at(i)) << endl;
	}
}

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

bool compare(pair< string, pair< int, int > > a, pair< string, pair< int, int > > b){
	if(a.second.first != b.second.first){
		return a.second.first > b.second.first;
	}
	
	return a.second.second < b.second.second;
}

int main(){
	int n;
	vector< pair< string, pair< int, int > > > team;
	
	while(cin >> n, n){
		team.clear();
		team.resize(n);
		
		string str;
		int s, w, l;
		
		for(int i = 0; i < n; ++i){
			cin >> str;
			w = l = 0;
			for(int j = 0; j < n - 1; ++j){
				cin >> s;
				if(s == 0) ++w;
				else if(s == 1) ++l;
			}
			
			team[i] = make_pair< string, pair< int, int > >(str, make_pair< int, int >(w, l) );
		}
		
		sort(team.begin(), team.end(), compare);
		
		for(vector< pair< string, pair< int, int > > >::iterator it = team.begin(); it != team.end(); ++it){
			cout << it->first << endl;
		}
		
	}
	
	return 0;
}

C++: #include <iostream>
#include <map>
#include <sstream>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.baseballchamp", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		int n;
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if
		
		multimap< pair<int,int>, char > rank;
 
		int i,j;
		for (i = 0; i < n; ++i){
			getline (cin, str );
			char name;
			int in;
			int win = 0, lose = 0;
			
			stringstream ss(str);
			ss >> name;
			
			for (j = 0; j < n - 1; ++j){
				ss >> in;
				switch (in ){
					case 0: ++win; break;
					case 1: ++lose; break;
//					case 2: ++draw; break;
				} // end switch
			} // end for
			rank.insert (make_pair (make_pair (-win, lose ),name ) );
		} // end for
		
		multimap<pair <int, int> ,char >::iterator it = rank.begin();
			
		for (; it != rank.end(); ++it ){
//			cout << (*it).first.first << ' ' << (*it).first.second << ' ';
			cout << (*it).second << endl;
		} // end for
	} // end loop
		
	return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
#include<stdio.h>
#include<cstdio>
#include<math.h>
using namespace std;
int main(){
    int n,score,sum[10000],memo=0,max=-100;
    char ch[100],tem;
    while(1){
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>ch[i];
        for(int j=0;j<n-1;j++){
            cin>>score;
            if(score==0){
                memo+=1;
            }
            else if(score==1){
                memo-=1;
            }
        }
        sum[i]=memo;
        memo=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(sum[j]>max){
                max=sum[j];
                tem=ch[j];
                memo=j;
            }
        }
        cout<<tem<<endl;
        sum[memo]=-100;
        max=-100;
    }
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>

using namespace std;
long long int sum[9];
int main(void)
{
	char name[10];
	int toku[9][5],n,make,kati,hiki,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;
				}
			}
		}
	}
}