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 <algorithm>
#include <map>
#include <vector>
#include <functional>

using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

int main(void){
	while(1){
		int a,n;
		string s;
		vector< pair<int,string> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.push_back(make_pair(w*3+d,s));
		}
		stable_sort(P.begin(),P.end(),cmp);
		for(a=0;a<n;a++){
			cout << P[a].second << "," << P[a].first << endl; 
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        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]+=',';
        }
        cout<<endl;
        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;
        }
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    vector<pair<string,int> > s;
    for(int i=0;i<n;i++){
      string str;cin>>str;
      int w,l,d;cin>>w>>l>>d;
      s.push_back(make_pair(str,w*3+d));
    }
    sort(s.begin(),s.end());
    for(int i=n-1;i>=0;i--)
      cout<<s[i].first<<","<<s[i].second<<endl<<endl;;
  }
  return 0;
}

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

struct cell{
	string name;
	int n;
};

bool compare(const cell& left, const cell& right)
{
	return left.n > right.n ;
}

int main()
{
	vector<cell> team;
	vector<cell>::iterator it;
	cell c;
	int n, i;
	string s;
	int w, l, d;
	bool f = false;
	while (cin>>n, n) {
		if (f) cout<<endl;
		f = true;
		team.clear();
		for (i = 0; i < n; i++) {
			cin>>s>>w>>l>>d;
			c.name = s;
			c.n = 3*w+d;
			team.push_back( c );
		}
		sort(team.begin(), team.end(), compare);
		for (i = 0; i < n; i++)
			cout<<team[i].name<<","<<team[i].n<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<pair<PII,string> > data;
    REP(i,n){
      string team;
      int win,tmp;
      cin>>team;
      cin>>tmp;
      win=tmp*3;
      cin>>tmp;
      cin>>tmp;
      win+=tmp;
      data.push_back(pair<PII,string>(PII(-win,i),team));
    }
    sort(data.begin(),data.end());
    REP(i,n){
      printf("%s,%d\n",data[i].second.c_str(),-data[i].first.first);
    }
    cout<<endl;
  }


  return 0;
}

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

int main(){

	bool f = false;
	while(true) {

		int n;
		cin >> n;
		if ( n == 0 ) break;
		if ( f ) cout << endl;

		vector<string> country;
		vector<int> score;
		string input1;
		int input2,input3,input4;
		vector<bool> flag;

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

			int cnt = 0;
			cin >> input1 >> input2 >> input3 >> input4;
			country.push_back(input1);
			cnt += ( input2*3 + input4 ) * 10 + ( 9 - i );
			score.push_back(cnt);
			flag.push_back(true);

		}

		sort( score.begin(), score.end() );
		for ( int i = n-1; i >= 0; i-- ) {
			cout << country[ 9 - score[i]%10 ] << "," << score[i]/10 << endl;
		}
		f = true;
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int main(){
    int n;
    while(cin>>n,n){
        priority_queue<pair<int,string>, vector<pair<int,string> >, less<pair<int,string> > >p;
        while(n--){
            string s;
            int a,b,c;
            cin>>s>>a>>b>>c;
            p.push(make_pair(3*a+c, s));
        }
        while(p.size()){
            pair<int,string>r=p.top();
            p.pop();
            cout<<r.second<<","<<r.first<<endl;
        }
    }
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	bool f=false;
	while(cin>>n){
		if(!n)break;
		vector<pair<int,string> > teams;
		for(int i=0,w,l,d;i<n;++i){
			string team;
			cin>>team>>w>>l>>d;
			teams.push_back(make_pair(w*3+d,team));
		}
		stable_sort(teams.begin(),teams.end());
		if(f)cout<<endl;
		else f=true;
		for(vector<pair<int,string> >::reverse_iterator it=teams.rbegin();it!=teams.rend();++it) cout<<(*it).second<<","<<(*it).first<<"\n";
	}
	return 0;
}

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];
					
				}
			}
			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;
		}
	}

	return 0;
}