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++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

void solve(MuMIS &result){
	foreach_it(MuMIS, it, result){
		cout << (*it).second << "," << (*it).first << endl;
	}
}

int main(){
	fastIO;
	int n, a = 0, b = 0, c = 0;
	string teamName;
	cin >> n;
	while (n){
		MuMIS result;
		while (n--){
			cin >> teamName >> a >> b >> c;
			result.insert(MP(a * 3 + c, teamName));
		}
		solve(result);
		cin >> n;
		if (n)
			cout << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (int)(count); i++)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 100000 ;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

using namespace std;

bool CMP(const pair<int,string>&x, const pair<int,string>&y){
	return x.first > y.first;
}

int main()
{
	int n; 
	while(cin>>n,n){
		vector<pair<int,string> > v;
		while(n--){
			string s; int a,b,c;
			cin>>s>>a>>b>>c;
			v.push_back(make_pair(a*3+c,s));
		}

		stable_sort(v.begin(),v.end(),CMP);
		FOR(i,sz(v)){
			cout << v[i].second << "," << v[i].first << endl;
		}
		cout << endl;
	}

	return 0;
}

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

int main(void)
{
	//チームの名前
	char str_name[10][21];
	//点数配列
	int h_point[10] = {0};
	//勝ち、負け、引き分けの入力変数
	int win = 0 , loss = 0 , drow = 0;
	//入力数
	int n = 0;
	int i = 0 , j = 0;
	//１番大きい要素を取り出す
	int index = 0;
	//最大値の設定変数
	int max = 0;
	//入れ替える文字列
	char str_tmp[11];
	int team = 0;
	//アクセス順配列
	int h_zyunban[10] = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9};

	while (true)
	{
		//参加チーム
		scanf("%d" , &team);

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

		for (int i = 0; i < team; i++)
		{
			//名前と得点の読み込み
			scanf("%s %d %d %d", str_name[i] , &win , &loss , &drow);
			h_point[i] = win * 3 + drow;
		}

		//ソート
		for (int i = 0; i < team - 1; i++)
		{
			for (int j = i + 1; j < team; j++)
			{
				if (h_point[i] < h_point[j])
				{
					//交換
					int tmp = h_zyunban[i];
					h_zyunban[i] = h_zyunban[j];
					h_zyunban[j] = tmp;

					tmp = h_point[i];
					h_point[i] = h_point[j];
					h_point[j] = tmp;
				}
			}
		}

		//出力
		for (int i = 0; i < team; i++)
		{
			printf("%s,%d\n" , str_name[h_zyunban[i]] , h_point[i]);
		}

		for (int i = 0; i < 10; i++)
		{
			h_zyunban[i] = i;
		}
	}
}

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

using namespace std;

int main(void){
	bool 	first=true;
	string	team;
	int	w,d,l;

	for(int n;cin >> n,n;){
		pair<string,int> *val,tmp;

		val = new pair<string,int>[n];

		for(int i=0;i<n;i++){
			cin >> team >> w >> l >> d;
			val[i]=make_pair(team,w*3+d);
		}

		for(int i=0;i<n-1;i++)
			for(int j=0;j<n-i-1;j++)
				if(val[j].second<val[j+1].second){
					tmp=val[j];
					val[j]=val[j+1];
					val[j+1]=tmp;
				}

		if(!first)
			cout << endl;
		else
			first=false;

		for(int i=0;i<n;i++)
			cout << val[i].first << "," << val[i].second << endl;
		delete [] val;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,string> Team;
main(){
  int n;
  int cnt=0;
  int kati,make,hikiwake;
  while(1){
    cin>>n;
    if(n==0)break;
    if(cnt!=0){
      cout<<endl;
    }
    Team team[100];
    for(int i=0;i<n;i++){
      cin>>team[i].second>>kati>>make>>hikiwake;
      team[i].first.first=-(kati*3+hikiwake);
      team[i].first.second=i;
    }
    sort(team,team+n);
    for(int i=0;i<n;i++){
      cout<<team[i].second<<','<<-team[i].first.first<<endl;
    }
    cnt++;
  }
}

C++: #include<iostream>
#include<map>
#include<algorithm>

using namespace std;

typedef struct{
  string name;
  int sum;
}TEAM;

int main(){
  int rev = 0;
  int num;
  while(cin >> num && num){
    if(rev) cout << endl;
    rev++;
    map <string , int> M;
    int win, lose, draw;
    TEAM team[num];
    for(int i = 0; i < num; i++){
      cin >> team[i].name >> win >> lose >> draw;
      team[i].sum = win*3 + draw;
    }
    for(int i = 0; i < num-1; i++){
      for(int j = i; j < num; j++){
	if(team[i].sum < team[j].sum){
	  TEAM tmp = team[i];
	  team[i] = team[j];
	  team[j] = tmp;
	}
      }
    }
    for(int i = 0; i < num; i++){
      cout << team[i].name <<"," << team[i].sum<<endl;
    }
  }
  return 0;
}