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;

int main(){
    
    int n;
    while(cin >> n && n)
    {
    	string str;
    	int a,b,c;
    	vector<string>list;
    	int num[1000]={};
    	int count=0;

    	while(n--)
    	{
    		cin >> str >> a >> b >> c;
    		num[count]=a*3+c;
    		list.push_back(str);
    		count++;
    	}

    	for(int i=0;i<count;i++)
    	{
    		for(int j=i;j<count;j++)
    		{
    			if(num[i]<num[j])
    			{
    				swap(num[i],num[j]);
    				swap(list[i],list[j]);
    			}
    		}
    	}
    	for(int i=0;i<count;i++)
    	{
    		cout << list[i] << "," << num[i] << endl;
    	}
    	cout << endl;
    }
    return 0;
}

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;
        if(fl == 1) cout << endl << endl;
        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++){
            if(i == cnt-1) cout << data[i].name << "," << data[i].total;
            else cout << data[i].name << "," << data[i].total << endl;
        }
        fl = 1;
    }
}

C++: =#include <iostream>
#include <string>

using namespace std;

struct Team {
	string name;
	int score;
};

int main() {

	int n;
	bool test = true;

	while (cin >> n && n != 0) {

		if (!test)
			cout << "\n";

		Team *team = new Team[n];
		int w, l, d;

		for (int i = 0; i < n; i++) {

			cin >> team[i].name >> w >> l >> d;
			team[i].score = w * 3 + d;


		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (team[i].score > team[j].score)
					swap(team[i], team[j]);
			}
		}

		for (int i = 0; i < n; i++)
			cout << team[i].name << "," << team[i].score << "\n";

		if (test)
			test = false;

	}


	return 0;

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

struct T{string n; int p; };

bool operator==(const T& l, const T& r)
{
    return l.p == r.p;
}

bool operator>(const T& l, const T& r)
{
    return l.p < r.p;
}

bool operator<(const T& l, const T& r)
{
    return l.p > r.p;
}


int main()
{
    int n;
    bool fst = true;
    while(cin >> n && n) {
        if(fst) {
            fst = false;
        } else {
            cout << endl;
        }
        T v[n];
        int a, b, c;
        for(int i = 0; i < n; i++) {
            cin >> v[i].n >> a >> b >> c;
            v[i].p = a * 3 + c;
        }
        stable_sort(v, v + n);
        for(int i = 0; i < n; i++) {
            cout << v[i].n << "," << v[i].p << endl;
        }
    }
}

C++: #include<stdio.h>
#include<string.h>

int main()
{
	char coun[11][21];
	int score[11],win,lose,draw,max[11];
	int i,j,n;
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",coun[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
			max[i]=score[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(max[i]>max[j]){
					max[10]=max[i];
					max[i]=max[j];
					max[j]=max[10];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(max[i]==score[j]){
					printf("%s,%d\n",coun[j],score[j]);
					score[j]=-1;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Result{
	string name;
	int score;
	Result(){}
	Result(string n,int s):name(n),score(s){}
	bool operator>(const Result& r)const{return score>r.score;}
};

int main()
{
	for(int n;cin>>n,n;){
		vector<Result> rs(n);
		rep(i,n){
			int a,b,c;
			cin>>rs[i].name>>a>>b>>c;
			rs[i].score=a*3+c;
		}
		stable_sort(allof(rs),greater<Result>());
		rep(i,n)
			cout<<rs[i].name<<","<<rs[i].score<<endl;
		cout<<endl;
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	int n, i, j;
	char team[10][21] = {0};
	int game[10][3] = {0};
	int point[10] = {0};
	char temp1[21] = {0};
	int temp2;

	while (scanf("%d%*c", &n) != EOF)
	{
		if (n == 0)
			break;

		for (i = 0; i < n; i++)
		{
			scanf("%s %d %d %d%*c", team[i], &game[i][0], &game[i][1], &game[i][2]);
			point[i] = game[i][0] * 3 + game[i][2];
		}

		for (j = 0; j < n - 1; j++)
			for (i = 0; i < n - 1; i++)
				if (point[i] < point[i+1])
				{
					strcpy(temp1, team[i]);
					strcpy(team[i], team[i+1]);
					strcpy(team[i+1], temp1);

					temp2 = point[i];
					point[i] = point[i+1];
					point[i+1] = temp2;
				}

		for (i = 0; i < n; i++)
			printf("%s,%d\n", team[i], point[i]);
	}

	return 0;
}

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

using namespace std;

int main() {

	int n, f=0;

	while(cin >> n, n!=0) {
		if(!f) {
			f=1;
		}
		else {
			cout << endl;
		}
		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++;
		}
		team. clear();
	}

	return 0;

}