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<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    bool flg = 0;
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        if(flg == 1) cout << endl;
        char team[20][100] = {0};
        int ten[20] = {0};
        int mx = 0;
        for(int i = 0; i < n; i++){
            getchar();
            scanf("%s",team[i]);
            int a,b,c;
            cin >> a >> b >> c;
            ten[i] = 3 * a + c;
            mx = max(mx,ten[i]);
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(ten[i] > ten[j]){
                    swap(ten[i],ten[j]);
                    swap(team[i],team[j]);
                }
            }
        }
        for(int i = 0; i < n; i++) printf("%s,%d\n",team[i],ten[i]);
        flg = 1;
	}
	return 0;
}

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

void sort(string s[], int a[], int n) {
  for (int i = 0; i < n; i++) {
    for (int j = i; j > 0; j--) {
      if (a[j - 1] < a[j]) {
	int t = a[j - 1];
	a[j - 1] = a[j];
	a[j] = t;
	string u = s[j - 1];
	s[j - 1] = s[j];
	s[j] = u;
      }
    }
  }
}

int main() {
  bool flag = false;
  for ( ; ; ) {
    int n;
    cin >> n;
    if (n == 0) return 0;
    if (flag) cout << endl;
    else flag = true;
    string s[n];
    int w[n], l[n], d[n], score[n];
    for (int j = 0; j < n; j++)
      cin >> s[j] >> w[j] >> l[j] >> d[j];
    for (int j = 0; j < n; j++)
      score[j] = w[j] * 3 + d[j];
    
    sort(s, score, n);
    for (int j = 0; j < n; j++)
      cout << s[j] << ',' << score[j] << endl;
  }
}

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

//勝敗構造体
typedef struct struct_point
{
	int win;
	int loss;
	int drow;
}S_point;

//データ構造体
typedef struct struct_data
{
	char name[21];
	S_point s_point;
	int point;
}S_data;

int main(void)
{
	//入力数
	int n = 0;
	//交換構造体
	S_data s_tmp;
	S_data *ptr_tmp = &s_tmp;

	S_data s_data[10] = {0};

	bool flag = true;

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			return 0;
		}

		if (flag == true)
		{
			flag = false;
		}
		else
		{
			cout << endl;	
		}

		for (int i = 0; i < n; i++)
		{
			cin >> s_data[i].name >> s_data[i].s_point.win >> s_data[i].s_point.loss >> s_data[i].s_point.drow;
			s_data[i].point = s_data[i].s_point.win * 3 + s_data[i].s_point.drow;
		}

		//ソート
		for (int i = 0; i < n - 1; i++)
		{
			*ptr_tmp = s_data[i];
			int index = i;
			for (int j = i + 1; j < n; j++)
			{
				if (ptr_tmp->point < s_data[j].point)
				{
					index = j;
					*ptr_tmp = s_data[j];
					/*
					*ptr_tmp = s_data[i];
					s_data[i] = s_data[j];
					s_data[j] = *ptr_tmp;
					*/
				}
			}
			s_data[index] = s_data[i];
			s_data[i] = *ptr_tmp;
		}

		for (int i = 0; i < n; i++)
		{
			//cout << s_data[i].name << "," << s_data[i].point << endl;
			cout << s_data[i].name << "," <<s_data[i].point << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
struct Team { string name; int score; };
bool cmp(const Team &a, const Team &b) { return a.score > b.score; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    bool flag = false;
    while(true)
    {
        int n; cin >> n;
        if(n == 0) break;
        if(flag) cout << endl;
        vector<Team> v(n);
        for(int i = 0; i < n; i++)
        {
            string name; cin >> name;
            int w, l, d; cin >> w >> l >> d;
            int s = w * 3 + d;
            v[i] = {name, s};
        }
        stable_sort(v.begin(), v.end(), cmp);
        for(int i = 0; i < v.size(); i++) cout << v[i].name << "," << v[i].score << endl;
        flag = true;
    }
    return 0;
}

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

int main()
{
	bool flag = true;
	while (1)
	{
		vector< pair<int, string> > team;
		int n;
		cin >> n;
		if (n == 0) { break; }

		for (int i = 0; i < n; ++i)
		{
			string t;
			int a, b, c;

			cin >> t >> a >> b >> c;

			team.push_back(make_pair(a * 3 + c, t));
		}

		if (flag) flag = false;
		else cout << endl;

		sort(team.begin(), team.end());

		for (int i = team.size() - 1; i >=0; --i)
		{
			cout << team[i].second << "," << team[i].first << endl;
		}

	}

	return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
string s[11];
int w[11], l[11], d[11], p[11];
bool used[11];

int main() {
	while (cin >> n&&n) {
		REP(i, n) {
			used[i] = false;
			cin >> s[i] >> w[i] >> l[i] >> d[i];
			p[i] = 3 * w[i] + d[i];
		}
		REP(i, n) {
			int maxp = -2;
			string maxc;
			int maxj = 0;
			REP(j, n) {
				if (maxp < p[j]&&!used[j]) {
					maxp = p[j];
					maxc = s[j];
					maxj = j;
				}
			}
			cout << maxc << "," << maxp << endl;
			used[maxj] = true;
		}
		cout << endl;
	}
}