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 <iostream>
#include <algorithm>
struct team{
	std::string name;
	int point;
	int n;
};

bool tsort(const team& a,const team& b){
	if(a.point - b.point){
		return a.point > b.point;
	}
	return a.n < b.n;
}

int main(){
	int n;
	bool f = false;
	while(std::cin>>n,n){
		if(f)std::cout<<std::endl;
		else{f=true;}
		team all[10];
		for(int i = 0;i < n;i++){
			std::string name;
			int w,d,l;
			std::cin>>name>>w>>l>>d;
			team t = {name,w*3+d,i};
			all[i] = t;
		}
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<all[i].point<<std::endl;
		}
	}
	return 0;
}

C++: #include <functional>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}

		multimap<int, string, greater<int>> team;
		for(int i=0; i<n; i++) {
			int a, b, c;
			char s[32];
			cin >> s >> a >> b >> c;
			team.insert(map<int, string>::value_type((3*a+c), s));
		}
		
		multimap<int, string, greater<int>>::iterator it=team.begin();
		while(it!=team.end()) {
			cout << (*it).second << "," << (*it).first << endl;
			it++;
		}
	}

	return 0;

}

C++: #include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};

int main()
{
	int n;
	while (cin >> n && n)
	{
		vector< pair <int, string> > a;
		for (int i = 0; i < n; i++)
		{
			int p = 0;
			string name;
			cin >> name;
			p += in() * 3; in();
			p += in();

			a.push_back(pair<int, string>(p, name));
		}

		for (int l = 0; l <= n; l++)
		{
			for (int i = 1; i < a.size(); i++)
			{
				if (a[i].first > a[i - 1].first)swap(a[i], a[i - 1]);
			}
		}

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

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    bool first = true;

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<pair<int, int>, string> > score(n);
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> score[i].second >> a >> b >> c;
            score[i].first.first = 3 * a + c;
            score[i].first.second = i;
        }

        sort(score.rbegin(), score.rend());
        if(first)
            first = false;
        else
            cout << endl;
        for(int i=0; i<n; ++i){
            cout << score[i].second << ',' << score[i].first.first << endl;
        }
    }
}

C++: #include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;

int N,sum[10],sum2[10];
struct DATA{
	string country;
	int win,lose,drow,sum,flag; 
};
DATA data[11];
int main(void){
	while(1){
		for(int i=0;i<N;i++){data[i]=data[11];sum[i]=0;sum2[i]=0;}
		cin>>N;
		if(N==0){break;}
		for(int i=0;i<N;i++){
			cin>>data[i].country>>data[i].win>>data[i].lose>>data[i].drow;
			data[i].sum=data[i].win*3+data[i].drow;
			sum[i]=data[i].sum;
		}
		sort(sum,sum+N);
		for(int i=0;i<N;i++){sum2[i]=sum[N-1-i];}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(sum2[i]==data[j].sum && data[j].flag==0){
					cout<<data[j].country<<","<<data[j].sum<<endl;
					data[j].flag=1;
					break;
				}
			}
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <map>
using namespace std;

int main() {
    int a,b,c,n,f=0;
	string st;
	map<int,string> mp;
	map<int,string>::reverse_iterator it;
	while (cin >> n) {
		if (n==0) break;
		for (n--;n>=0;n--) {
			cin >> st >> a >> b >> c;
			mp.insert(map<int,string>::value_type((a*3+c)*10+n,st));
		}
    if (f==0) f=1; else cout << endl;
	for (it=mp.rbegin();it!=mp.rend();it++) cout << (*it).second << ',' << (*it).first/10 << endl;
	mp.clear();
	}
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    bool kawa;
    while(cin>>n,n){
        if(kawa)cout<<endl;
        string str[10];
        int num[10];
        for(int i=0,win,lose,draw;i<n;i++){
            cin>>str[i]>>win>>lose>>draw;
            num[i]=win*3+draw;
            str[i]+=',';
        }
        for(int i=0;i<n;i++){
            int ma=0;
            for(int j=0;j<n;j++)if(num[ma]<num[j])ma=j;
            cout<<str[ma]<<num[ma]<<endl;
            num[ma]=-1;
        }
        kawa=1;
    }
}

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

struct P{
    string name;
    int win;
    int lose;
    int even;
    int total;
    static bool more (const P& left,const P& right){
        return left.total > right.total;
    }
};

int main(){
    int n;
    int fl=0;
    int cnt;
    while(1){
        cnt = 0;
        cin >> n;
        if(n == 0) break;
        vector <P> data;
        P tmp;
        for(int i=0;i<n;i++){
            cin >> tmp.name >> tmp.win >> tmp.lose >> tmp.even;
            tmp.total = tmp.win*3 + tmp.even;
            data.push_back(tmp);
            cnt++;
        }
        sort(data.begin(),data.end(),P::more);
        for(int i=0;i<cnt;i++){
            cout << data[i].name << "," << data[i].total << endl;
        }
        if(fl == 0){
            fl = 1;
            cout << endl;
        }
        else if(fl == 1) fl = 0;
    }
}