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 <string>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	bool next = false;
	int n;
	while ( cin >> n && n )
	{
		if ( next )
		{
			cout << endl;
		}
		next = true;
		vector <string> team_names(n);
		vector <int> points(n,0);
		vector <int> id(n,0);
		for ( int i = 0; i < n; i++ )
		{
			id[i] = i;
			cin >> team_names[i];
			int point;
			cin >> point;
			points[i] += point * 3;
			cin >> point;
			cin >> point;
			points[i] += point;
		}

		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i + 1; j < n; j++ )
			{
				if ( points[i] < points[j] )
				{
					swap( points[i], points[j] );
					swap( team_names[i], team_names[j] );
					swap( id[i], id[j] );
				}
				else if ( points[i] == points[j] )
				{
					if ( id[i] > id[j] )
					{
						swap( points[i], points[j] );
						swap( team_names[i], team_names[j] );
						swap( id[i], id[j] );
					}
				}
			}
		}

		for ( int i = 0; i < n; i++ )
		{
			cout << team_names[i] << ',' << points[i] << endl;
		}

	}

	return 0;
}

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

using namespace std;
typedef pair<string, int> P;
void solve()
{
	int n;
	bool flag = false;
	while(cin >> n, n)
	{
		if(flag)
		{
			cout << endl;
		}
		flag = true;
		vector<P> data(n);
		int temp[3];
		for(int i = 0; i < n; ++i)
		{
			cin >> data[i].first >> temp[0] >> temp[1] >> temp[2];
			data[i].second = temp[0] * 3 + temp[2];
		}
		
		for(int i = 0; i < n; ++i)
		{
			for(int j = n - 1; j > i; --j)
			{
				if(data[j].second > data[j - 1].second)
				{
					P a = data[j];
					data[j] = data[j - 1];
					data[j - 1] = a;
				}
			}
		}
		for(int i = 0; i < n; ++i)
		{
			cout << data[i].first << "," << data[i].second << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(_Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,_Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int main(){
    int n;
    bool f = false;
    while(cin >> n && n){
        map<int,int> m;
        vector<string> ss(n);
        multimap<int,int,greater<int> > mm;
        string s;
        int w,l,d;
        if(f) cout << endl;
        REP(i,n){
            cin >> s >> w >> l >> d;
            ss[i] = s;
            m[i] += (w*3+d);
        }
        FOREACH(it,m)
            mm.insert(mp(it->second,it->first));
        FOREACH(it,mm)
            cout << ss[it->second] << "," << it->first << endl;
        f = true;
    }
    return 0;
}

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

using namespace std;

class Team{
public:
	string name;
	int win;
	int lose;
	int draw;
	int point;

};
bool operator<( const Team& rhs, const Team& lhs ){
	return ( rhs.point < lhs.point );
}
bool operator>( const Team& rhs, const Team& lhs ){
	return ( rhs.point > lhs.point );
}
int main(int argc, char const* argv[])
{
	int num;
	Team team[10];
	bool a = false;

	while( cin >> num && num != 0 ){
		if( a == true ) cout << endl;
		a = true;
		for( int i = 0;i < num;i++ ){
			cin >> team[i].name >> team[i].win >> team[i].lose >> team[i].draw;
			team[i].point = team[i].win * 3 + team[i].draw;
		}
		stable_sort( team, team + num, greater<Team>() );
		for( int i = 0;i < num;i++ ) cout << team[i].name << "," << team[i].point << endl;
	}
	return 0;
}