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<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct data{
    int w,l,p;
    char name;
    data(int a,int b,int c,char d):w(a),l(b),p(c),name(d){}
    data(){}
    bool operator<(const data &d)const{
        if(w!=d.w)return w<d.w;
        if(l!=d.l)return l>d.l;
        return p>d.p;
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        vector<data>V;
        for(int i=0;i<n;i++){
            char c;
            scanf(" %c",&c);
            int w,l;
            w=l=0;
            for(int j=0;j<n-1;j++){
                int val;
                scanf("%d",&val);
                if(val==2)continue;
                if(val)w++;
                else l++;
            }
            V.push_back(data(w,l,i,c));
        }
        sort(V.begin(),V.end());
        for(int i=0;i<n;i++){
            printf("%c\n",V[i].name);
        }

    }
    return 0;
}

C++: #include<iostream>
#include<utility>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<pair<pair<double, double>,char>> results;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		double win, lose,result;
		for (int i = 0; i < n;++i) {
			cin >> name;
			win = 0.0, lose = 0.0;
			for (int j = 0; j < n - 1; ++j) {
				int r;
				cin >> r;
				if (r == 2)continue;
				else if (r == 0)win++;
				else lose++;
			}
			results.emplace(make_pair(make_pair(win,-lose),name));
		}
		while(!results.empty()) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void){
	int a,b;
	while(1){
		int max=-1;
		char c[5];
		c[0]= 'A';
		c[1]= 'B';
		c[2]= 'C';
		c[3]= 'D';
		c[4]= 'E';
		int maxchar=0;
		cin >> a >> b;
		if(a == 0  && b == 0) break;
		for(int i=0;i<5;i++){
			if(max < a+b) {
				max =a+b;
				maxchar=i;
			}
		}
		cout << c[maxchar] << " " << max << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<int,pll> P;
int main(){
  while(1){
    map<int,string> mp;
    int n,i,j;
    cin >> n;
    if(n==0){
      return 0;
    }
    vector<P> p;
    for(i=0;i<n;i++){
      string s;
      cin >> s;
      mp[i]=s;
      int win=0,lose=0;
      for(j=0;j<n-1;j++){
        int a;
        cin >> a;
        if(a==0){
          win++;
        }
        else if(a==1){
          lose++;
        }
      }
      p.push_back(make_pair(-win,pll(lose,i)));
    }
    sort(p.begin(),p.end());
    for(i=0;i<n;i++){
      cout << mp[p[i].second.second] << endl;
    }
  }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    char t[n];
    char kt;
    int tt[2][n];
    int k;
    int h;
    for(int i=0;i<2;i++){
      for(int j=0;j<n;j++){
	tt[i][j] = 0;
      }
    }
    for(int i=0;i<n;i++){
      cin >> t[i];
      for(int j=0;j<n-1;j++){
	cin >> h;
	if(h==0) tt[0][i] += 1;
	if(h==1) tt[1][i] += 1;
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(tt[0][j]<tt[0][j+1]){
	  k = tt[0][j];
	  tt[0][j] = tt[0][j+1];
	  tt[0][j+1] = k;
	  k = tt[1][j];
	  tt[1][j] = tt[1][j+1];
	  tt[1][j+1] = k;
	  kt = t[j];
	  t[j] = t[j+1];
	  t[j+1] = kt;
	}
	/*else if(tt[0][j]==tt[0][j+1]&&tt[1][j]<=tt[1][j+1]){
    	  k = tt[0][j];
	  tt[0][j] = tt[0][j+1];
	  tt[0][j+1] = k;
	  k = tt[1][j];
	  tt[1][j] = tt[1][j+1];
	  tt[1][j+1] = k;
	  kt = t[j];
	  t[j] = t[j+1];
	  t[j+1] = kt;
	  }*/
      }
    }
    for(int i=0;i<n;i++) cout << t[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 <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, char> P;
typedef pair<int, P> PP;
 
bool compare(PP a, PP b)
{
    return a.first > b.first;
}
 
int main()
{
    int n, res[10];
    char ch;
 
    while (cin >> n, n) {
	vector<PP> v;
	for (int i = 0; i < n; i++) {
	    int sum = 0, f = 0;
	    cin >> ch;
	    for (int j = 0; j < n-1; j++) {
		cin >> res[j];
		if (res[j]==0) sum += 5;
		else if (res[j]==2) sum++;
		else f++;
	    }  
	    v.push_back(PP(sum, P(f, ch))); 
	}
	sort(v.begin(), v.end(), compare);
	for (int i = 0; i < n; i++) {
	    cout << v[i].second.second << endl;
	}
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
long long int sum[11];
int main(void)
{
	int i,j,k,n;
	int data;
	string name[11];
	while(1) {
		cin>>n;
		if(!n) break;
		for(i=0;i<n;i++) sum[i]=0;
		for(i=0;i<n;i++) {
			cin>>name[i];
			for(j=0;j<n-1;j++) {
				cin>>data;
				if(data==0) sum[i]+=100;
				else if(data==1) sum[i]--;
				else sum[i]+=15;
			}
		}
		for(i=0;i<n-1;i++) {
			for(j=i+1;j<n;j++) {
				if(sum[i]<sum[j]) {
					swap(sum[i],sum[j]);
					swap(name[i],name[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<name[i]<<endl;
	}
	return 0;
}