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<stdio.h>
#include<string.h>

int main(){
	char team[10][21],temp[21];
	int knit,n,win[10],lose[10],drow[10],wpt[10],i,j;
	
	for(;;){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%s%d%d%d",&team[i],&win[i],&lose[i],&drow[i]);
			wpt[i] = win[i] * 3 + drow[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(wpt[i]>wpt[j]){
					knit=wpt[j];
					wpt[j]=wpt[i];
					wpt[i]=knit;
					strcpy(temp,team[j]);
					strcpy(team[j],team[i]);
					strcpy(team[i],temp);
				}
			}
		}
		
		for(i=0;i<n;i++){
			printf("%s,%d\n",team[i],wpt[i]);
		}
		puts("");
	}
	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]+=',';
        }
        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<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;
	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;
	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]);
	}
		cout<<endl;
	}
	return 0;
}

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

typedef std::pair<int, std::string> P;

int n;
std::vector<P> v;

int main()
{
	bool fst = true;

	while( std::cin >> n, n )
	{
		v.clear();

		for( int i = 0; i != n; ++i )
		{
			std::string s;
			int a, b, c;
			std::cin >> s >> a >> b >> c;
			
			v.push_back( P( a * 3 + c, s ) );
		}

		std::stable_sort( v.rbegin(), v.rend() );

		if( !fst )
			std::cout << std::endl;
		for( int i = 0; i != n; ++i )
			std::cout << v[i].second << ',' << v[i].first << std::endl;
	
		fst = false;
	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j,k,x,n,setcnt;
	int win,lose,drow;
	char kuni[10][21];
	int tokuten[10];
	setcnt=0;
	while(1) {
		cin>>n;
		if(n==0)break;
		else if(setcnt!=0)cout<<endl;
		for(i=0;i<n;i++) {
			cin>>kuni[i]>>win>>lose>>drow;
			tokuten[i]=win*3+drow;
		}
		for(i=0;i<n;i++) {
			for(j=i+1;j<n;j++) {
				if(tokuten[i]<tokuten[j]) {
					swap(tokuten[i],tokuten[j]);
					swap(kuni[i],kuni[j]);
				}
			}
		}
		for(i=0;i<n;i++) cout<<kuni[i]<<","<<tokuten[i]<<endl;
		setcnt++;
	}
	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;
				}
			}	
		}
		printf("\n");
	}	
}

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

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

int main(void){
	int n ;
	bool o = false;
	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));
		}
		
		sort(v.begin(),v.end(),CMP);
		if(o)cout<<endl;
		o = true;
		for(int i = 0 ; i < v.size() ; i ++){
			cout<<v[i].second<<","<<v[i].first<<endl;
		}
	}
}

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

using namespace std;

int N;
typedef pair<int, int> P;
vector<string> mp;
vector<P> wp;

int comp(P a, P b) {
	return a.second > b.second;
}

int main() {
	while (true) {
		cin >> N;
		if (N == 0) {return 0;}
		mp.clear();
		wp.clear();
		for (int i = 0; i < N; i++) {
			string country;
			cin >> country;
			int w, d, l;
			cin >> w >> l >> d;
			mp.push_back(country);
			wp.push_back(P(i, 3 * w + d));
		}
		sort(wp.begin(), wp.end(), comp);
		for (int i = 0; i < wp.size(); i++) {
			cout << mp[wp[i].first] << "," << wp[i].second << endl;
		}
		cout << endl;
	}
}

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

typedef pair<int,int> P;
typedef pair<P,string> PP;

int main(void)
{
	PP team[10] = {};
	int n;
	int win,lost,draw;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> team[i].second;
		cin >> win >> lost >> draw;
		team[i].first.first = win*3+draw;
		team[i].first.second= win;
	}
	sort( team, team+10 );

	for(int i = 9; 10-i <= n; i--)
		cout << team[i].second << ',' << team[i].first.first << endl;


	return 0;
}

C++: #include<stdio.h>

int main()
{
	int score[11],win,lose,draw,point[11];
	int n,i,j;
	char str[11][21];
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",str[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
			point[i]=score[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]>point[j]){
					point[10]=point[i];
					point[i]=point[j];
					point[j]=point[10];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]==score[j]){
					printf("%s,%d\n",str[j],score[j]);
					score[j]=-1;
					break;
				}
			}
		}
		puts("");
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	bool f=false;
	while(cin>>n){
		if(!n)break;
		if(f)cout<<endl;
		f=true;
		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*1,team));
		}
		stable_sort(teams.begin(),teams.end());
		for(vector<pair<int,string> >::reverse_iterator it=teams.rbegin();it!=teams.rend();++it) printf("%s,%d\n",(*it).second.c_str(),(*it).first);
	}
	return 0;
}