Go: package main

import (
	"bufio"
	"fmt"
	"os"
		"strconv"
	"strings"
	"sort"
	)

var scanner = bufio.NewScanner(os.Stdin)

type Country struct {
	Name  string
	Score int
}

func (c Country) String() string {
	return fmt.Sprintf("%s,%d", c.Name, c.Score)
}

type ByScore []Country

func (a ByScore) Len() int           { return len(a) }
func (a ByScore) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByScore) Less(i, j int) bool { return a[i].Score > a[j].Score }

func main() {
	// countries := []Country{
	// 	{"japan", 3},
	// 	{"america", 4},
	// 	{"canada", 2},
	// }
	// sort.Sort(ByScore(countries))
	// fmt.Println(countries)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		countries := make([]Country, n)
		for i := range countries {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmp := new(Country)
			tmp.Name = input[0]
			var x int
			for j := 1; j < 4; j++ {
				switch j {
				case 1:
					x, _ = strconv.Atoi(input[j])
				case 2:
					x = 0
				case 3:
					x, _ = strconv.Atoi(input[j])
					x *= 3
				}
				tmp.Score += x
			}
			countries[i] = *tmp
		}
		sort.Sort(ByScore(countries))
		for _, v := range countries {
			fmt.Println(v)
		}
		fmt.Println()
	}
}

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

typedef long long ll;

struct hoge{
    int s, n;
    string name;
    hoge(int s, int n, string name) : s(s), n(n), name(name) { }
};
bool operator < (const hoge &a, const hoge &b){
    return a.s != b.s ? a.s > b.s : a.n < b.n;
}

int main(void){
    int count=0;
    while(true){
        int n;
        cin >> n;
        if(count !=0 && n!=0) cout << "\n";
        count++;
        if(n==0) break;
        vector<hoge> v;
        string name;
        int win;
        
        for(int i=0; i<n; i++){
            cin >> name;
            ll w, l, d;
            cin >> w >> l >> d;
            win=3*w+d;
            v.push_back(hoge(win, i, name));
        }
        sort(v.begin(), v.end());
        for(int i=0; i<n; i++){
            cout << v[i].name << "," << v[i].s << "\n";
        }
        
    }
     
     
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100],d[100],f[100],g[100],h,i,j,q;
	char z[100][100],x[100];
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++){
			g[i]=0;
			scanf("%s %d %d %d",z[i],&s[i],&d[i],&f[i]);
			g[i]=s[i]*3+f[i];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]<g[j]){
					h=g[i];
					g[i]=g[j];
					g[j]=h;
					strcpy(x, z[i]);
					strcpy(z[i], z[j]);
					strcpy(z[j], x);
				}
				if(g[i]==g[j]){
					if(s[i]>s[j]){
						q=s[i];
						s[i]=s[j];
						s[j]=q;
						h=g[i];
						g[i]=g[j];
						g[j]=h;
						strcpy(x, z[i]);
						strcpy(z[i], z[j]);
						strcpy(z[j], x);
					}
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%s,%d\n",z[i],g[i]);
		}
	}
	return 0;
}

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

// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// pair util
#define FST first
#define SND second

// range validator
#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

int const dx[] = {-1,0,1,0,-1,1,1,-1};
int const dy[] = {0,-1,0,1,-1,-1,1,1};

//////////////////////////////////////////////////////////////


int main() {
  int N;
  bool blank = 0;
  while(cin >> N && N) {
    if(blank) cout << endl;
    blank = 1;
    vector<pair<PII, string> > vec;
    for(int i=0; i<N; i++) {
      string s; cin >> s;
      int a, b, c;
      cin >> a >> b >> c;
      vec.push_back(MP(MP(-a*3-c*1, i), s));
    }
    sort(ALL(vec));
    
    EACH(it, vec) {
      cout << it->second << "," << -it->first.first << endl;
    }
  }
  
  
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;
 
int main(void){
    int count = 0;
    int n;
    while(1) {
        scanf("%d",&n);
        if(n == 0) break;
        if(count != 0) {
            cout << endl;
        }
        count = 1;
        
        vector<string> country(n);
        vector<int> point(n,0);
        vector<int> pointw(n,0);
        
        
        int lose,win,tie;
        rep(i,n) {
            cin >> country[i];
            scanf("%d",&win);
            scanf("%d",&lose);
            scanf("%d",&tie);
            point[i] = win*3 + tie;
            pointw[i] = win*3 + tie;
        }
        sort(point.begin(),point.end());
        int search;
        rep(i,n) {
            search = 0;
            while(pointw[search] != point[n-i-1]) search++;
            cout << country[search] << "," << point[n-i-1] << endl;
            pointw[search] = -1;
       }
    }
}

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

        int n,q=0;
        cin>>n;
        if(n==0){
            //cout<<endl;
            break;
        }
        cout<<endl;
        int w[20],l[20],d[20];
        int p[20];

        char team[20][40];


        for(int i=0;i<n;i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            p[i]=w[i]*3+d[i];
        }
        for(int i=3*n;i>=0;i--){
            for(int j=0;j<n;j++){
                if(p[j]==i){
                    cout<<team[j]<<","<<p[j]<<endl;
                    q++;
                }
            }

        }


        }
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <functional>
#include <list>


using namespace std;

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

int main(void){
	bool b=false;
	while(1){
		int a,n;
		string s;
		multimap<int, string, greater<int> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert(make_pair(w*3+d,s));
		}
		multimap<int, string, greater<int> >::iterator it = P.begin();
		while( it != P.end() )	{
			cout << (*it).first << ":" << (*it).second << endl;
			++it;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
using namespace std;
int main() {
	int n, i, j, k;
	int z = 0;
	while (1) {
		cin >> n;
		if (n == 0) break;
		vector < pair < int,string  > > x(n);
		for (int q = 0; q < n; q++) {
			cin >> x[q].second;
			cin >> i >> j >> k;
			x[q].first = 3 * i + k;
		}
		for (int q = 0; q < n; q++) {
			sort(x.begin(), x.end(), greater<pair<int, string>>());
		}
		for (int q = 0; q < n; q++) {
			if (q == 0) {
				if (z != 0)	cout << endl;
			}
			cout << x[q].second << ',' << x[q].first << endl;
			z = 1;
		}
	}

	return 0;
}