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

using namespace std;



int main(void)
{
	//入力変数
	pair<int, string>h_input[10];
	//いくつ入力するか
	int n = 0;
	//入力変数
	char str_input[100] = {NULL};

	while (cin >> n && n != 0)
	{
		//入力変数
		pair<int , pair<int , int> > tokuten;

		for (int i = 0; i < n; i++)
		{
			cin >> str_input;
			h_input[i].second = str_input;
			cin >> tokuten.first >> tokuten.second.first >> tokuten.second.second;
			//勝ちと負けの分だけ加算
			h_input[i].first = tokuten.first * 3 + tokuten.second.second;
		}

		stable_sort(h_input , h_input + n , greater<pair<int , string> >());

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

C++: #include<bits/stdc++.h>

using namespace std ;

struct s
{
	int p ;
	string tm ;
} ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int p1 ;
		s st[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{cout << i ;
			cin >> st[ i ].tm >> st[ i ].p >> p1 >> p1 ;
			st[ i ].p = st[ i ].p * 3 + p1 ;
		}

		for( int i = 0 ; i < n ; i++ )
		{
			for( int j = i + 1 ; j < n ; j++ )
			{
				if( st[ i ].p > st[ j ].p )
					swap( st[ i ] ,st[ j ] ) ;
			}
		}

		for( int i = n - 1 ; i >= 0 ; i-- )
			cout << st[ i ].tm << ' ' << st[ i ].p << endl ;

	}
	return 0 ;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<string>
#include<vector>
using namespace std;
typedef pair<int,string> P;
main(){
  vector<P> ar;
  P p;
  int n,a,b,c,f = 1;
  string s;
  while(1){
    cin >> n;
    if(n > 0 && f == 0)cout << endl;
    f = 0;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin >> s >> a >> b >> c;
      p.first = (a*3) + (c*1);
      p.second = s;
      ar.push_back( p );
    }
    sort( ar.begin() , ar.end() , greater<P>());
    for(int i=0;i<n;i++){
      cout << ar[i].second << ',' << ar[i].first << endl;
    }
    ar.clear();
  }
}

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

using namespace std;

int main()
{
	int n;
	int i,j,k;
	
	for(k=0;;k++)
	{
		cin >> n ;
		if(n==0)
			break;
		if(k!=0)
			cout << endl;
		string str[11];
		int win[11],lose[11],drow[11];
		int score[11]={0};
		int num[11];
		for(i=0;i<n;i++)
		{
			num[i]=i;
			cin >> str[i] >> win[i] >> lose[i] >> drow[i] ;
			score[i] = win[i]*3+drow[i];
		}
		for(i=0;i<n-1;i++)
		{
			for(j=i+1;j<n;j++)
			{
				if(score[i]<score[j])
				{
					int a;
					string aa;
					a=score[i];
					score[i]=score[j];
					score[j]=a;
					a=num[i];
					num[i]=num[j];
					num[j]=a;
					aa=str[i];
					str[i]=str[j];
					str[j]=aa;
				}
			}
		}
		for(i=0;i<n-1;i++)
		{
			for(j=i+1;j<n;j++)
			{
				if(score[i]==score[j] && num[i]>num[j])
				{
					int a;
					string aa;
					a=score[i];
					score[i]=score[j];
					score[j]=a;
					a=num[i];
					num[i]=num[j];
					num[j]=a;
					aa=str[i];
					str[i]=str[j];
					str[j]=aa;
				}
			}
		}
		
		for(i=0;i<n;i++)
		{
			cout << str[i] << "," << score[i] << endl;
		}
	}
}

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


int main(void){
	int n;
	bool o = 0 ;
	while(cin>>n,n){
		if(cnt ++ > 0)cout<<endl;
		string name[n];
		int sum[n],point;
		int rank[n];
		for(int i = 0 ; i < n ; i ++){
			cin>>name[i];
			cin>>point; //win
			sum[i]=point*3;
			cin>>point;	//lose;
			cin>>point; //drow
			sum[i]+=point;
			rank[i]=i;			
		}
		for(int i = 0 ; i < n ; i ++)
			for(int j = 0 ; j < n ; j ++){
				if(sum[rank[i]]>sum[rank[j]]){
					int t = rank[i];
					rank[i] = rank[j];
					rank[j] = t;
				}
			}
		if(o)cout<<endl;
		o = true;
		for(int i = 0 ; i < n ; i ++)
			cout<<name[rank[i]]<<","<<sum[rank[i]]<<endl;
	}
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a, b, c, d; pair<int, string> p[10];
int main() {
	while(scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) {
			cin >> p[i].second >> a >> b >> c;
			p[i].first = i - a * 3 - c;
		}
		sort(p, p + n);
		if(d++) printf("\n");
		for(int i = 0; i < n; i++) {
			cout << p[i].second << ',' << p[i].first << endl;
		}
	}
	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;
		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};

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			return 0;
		}
		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;
		}
	}

	return 0;
}

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

bool cmp(pair<int, int> d1, pair<int, int> d2){
    if(d1.first == d2.first){
        return d1.second < d2.second;
    }
    return d1.first > d2.first;
}

int main(){
    int n;
    int cnt = 0;
    while(cin >> n, n){
        if(cnt != 0) cout << endl;
        cnt++;
        string s[10];
        vector<pair<int, int> > d;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> s[i] >> a >> b >> c;
            d.push_back(make_pair(3 * a + c, i));
        }
        sort(d.begin(), d.end(), cmp);
        for(int i = 0; i < n; i++){
            cout << s[d[i].second] << "," << d[i].first << endl;
        }
    }
}