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>
using namespace std;

int main()
{
	pair <string, int> score[10] , tmp;
	int n, w, l, d;
	int flg = 0;
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		if (flg != 0) cout << endl;

		for (int i = 0; i < n; i++)
		{
			cin >> score[i].first >> w >> l >> d;
			score[i].second = w * 3 + d;
		}

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

		for (int i = 0; i < n; i++)
		{
			cout << score[i].first << "," << score[i].second << endl;
		}
		flg++;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,score[1000];
    while(1){
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }
    int max=-10000,count=0,j=0,s;bool bo=false;
    while(1){
        if(count==n){
            break;
        }
        for(int i=0;i<n;i++){
            if(score[i]>max){
                max=score[i];
                s=i;
            }
        }
        cout<<name[s]<<","<<score[s]<<endl;
        count++;
        score[s]=-10;
        max=-10000;
    }
    }
    return 0;
}

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


bool bless(const pair<int, int> &p, const pair<int, int> &q) {
  return (p.first != q.first) ? p.first > q.first : p.second < q.second;
}

int main() {
  int n,f=0;
  while(cin>>n, n) {
    if(f) cout<<endl;
    vector< pair<int, int> > v;
    vector<string> w;
    string s;
    int a,b,c;
    for(int i=0; i<n; ++i) {
      cin>>s>>a>>b>>c;
      v.push_back( pair<int,int>(a*3+c,i) );
      w.push_back(s);
    }

    stable_sort(v.begin(), v.end(), bless);

    for(int i=0; i<n; ++i)
      cout<<w[v[i].second]<<","<<v[i].first<<endl;
    f=1;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
using namespace std;
int main() {
	int n, i, j, k;
	int z = 0;
	while (1) {
		cin >> n;
		if (n == 0) break;
		vector < pair < int,string  > > x(n);
		for (int q = 0; q < n; q++) {
			cin >> x[q].second;
			cin >> i >> j >> k;
			x[q].first = 3 * i + k;
		}
		for (int q = 0; q < n; q++) {
			sort(x.begin(), x.end(), greater<pair<int, string>>());
		}
		for (int q = 0; q < n; q++) {
			if (q == 0) {
				if (z != 0)	cout << endl;
			}
			cout << x[q].second << ',' << x[q].first << endl;
			z = 1;
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main(void){
	int n,a,b,c,w[10],i,j,temp,x=0;
	char as[10][21];
	while(1){
		int s[10]={0,1,2,3,4,5,6,7,8,9};
	scanf("%d",&n); //???????????°
		if(n==0)break;
		if(x>0&&n!=0)cout<<endl;
		 cout<<endl;
	for(i=0;i<n;i++){
		scanf("%s%d%d%d",as[i],&a,&b,&c);
		w[i]=a*3+c;
	}
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(w[i]<w[j]){
				swap(w[i],w[j]);
				swap(s[i],s[j]);
			}
			else if(w[i]==w[j]){
				if(s[i]>s[j]){
					swap(s[i],s[j]);
				}
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s,%d\n",as[s[i]],w[i]);
	}
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,b[100],c[100],x,y,z,j,max;
	char a[100][100];
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			b[i]=0; c[i]=0;
		}	
		for(i=0;i<n;i++){
			scanf("%s %d %d %d",a[i],&x,&y,&z);
			b[i]=x*3+z;
		}
		for(i=0;i<n;i++){
			max=-1;
			for(j=0;j<n;j++){
				if(max<b[j]) max=b[j];
			}
			for(j=0;j<n;j++){
				if(max==b[j]){
					printf("%s,%d\n",a[j],b[j]);
					b[j]=-2;
				}
			}	
		}
	}	
}

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++)
		{
			for (int j = i + 1; j < n; j++)
			{
				if (s_data[i].point < s_data[j].point)
				{
					*ptr_tmp = s_data[i];
					s_data[i] = s_data[j];
					s_data[j] = *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<algorithm>
#include<string>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,string> pii;
int main(){
    int n;
    bool f=false;
    while(cin>>n,n){
        if(f)cout<<endl;
        string str;
        int W,L,D;
        vector<pii>V(n);
        for(int i=0;i<n;i++){
            cin>>str>>W>>L>>D;
            V[i]=pii(W*3+D,str);
        }
        stable_sort(V.rbegin(),V.rend());

        for(int i=0;i<V.size();i++){
            cout<<V[i].S<<","<<V[i].F<<endl;
        }
        f=true;
    }
}

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

int main() {
    bool insertLinefeed = false;
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        multimap<int, string> teams;
        set<int> scores;
        for (int i = 0; i < n; i++) {
            string team;
            int win, lose, draw;
            cin >> team >> win >> lose >> draw;
            teams.insert(make_pair(3 * win + draw, team));
            scores.insert(3 * win + draw);
        }
        if (insertLinefeed) {
            cout << endl;
        } else {
            insertLinefeed = true;
        }
        for (set<int>::reverse_iterator sit = scores.rbegin(); sit != scores.rend(); sit++) {
            for (multimap<int, string>::iterator it = teams.lower_bound(*sit); it != teams.upper_bound(*sit); it++) {
                cout << it->second << "," << it->first << endl;
            }
        }
    }
}