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++: //31
#include<iostream>
#include<algorithm>
#include<utility>
#include<string>

using namespace std;

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

int main(){
  bool sec=false;
  for(int n;cin>>n,n;){
    pair<string,int> a[10];
    for(int i=0;i<n;i++){
      string s;
      int w,l,d;
      cin>>s>>w>>l>>d;
      a[i]=make_pair(s,w*3+d*1);
    }
    stable_sort(a,a+n,cmp);
    if(sec){
      cout<<endl;
    }
    sec=true;
    for(int i=0;i<n;i++){
      cout<<a[i].first<<','<<a[i].second<<endl;
    }
  }
  return 0;
}

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

std::pair<std::string,int> team[10];

int main()
{
	int n,win,lose,draw,point;
	std::string name;
	
	while(1)
	{
		std::cin>>n;
		if(n==0)break;
		
		for(int i=0;i<n;i++)
		{
			std::cin>>name>>win>>lose>>draw;
			point=win*3+draw;
			team[i].first=name;
			team[i].second=point;
		}
		
		for(int i=0;i<n;i++)
		{
			for(int j=i;j>0&&team[j].second>team[j-1].second;j--)
			{
				std::pair<std::string,int> temp;
				temp=team[j];
				team[j]=team[j-1];
				team[j-1]=temp;
			}
		}
		for(int i=0;i<n;i++)
		{
			std::cout<<team[i].first<<','<<team[i].second<<std::endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

typedef struct {
	int sum;
	char name[20];
} TEAM;

int main()
{
	int n;
	int win, lose, drow;
	bool flg = 0;
	TEAM team[10];

	while (1){
		scanf("%d", &n);

		if (n == 0){
			break;
		}

		if (flg == false){
			flg = true;
		}
		else {
			cout << endl;
		}

		for (int i = 0; i < n; i++){
			scanf("%s %d %d %d", team[i].name, &win, &lose, &drow);
			team[i].sum = win * 3 + drow;
		}

		char tmp[10];
		int n_tmp;

		for (int i = 0; i < n; i++){
			for (int j = n - 1; j > i; j--){
				if (team[j].sum > team[j - 1].sum){
					strcpy(tmp, team[j - 1].name);
					n_tmp = team[j - 1].sum;

					strcpy(team[j - 1].name, team[j].name);
					team[j - 1].sum = team[j].sum;
					
					strcpy(team[j].name, tmp);
					team[j].sum = n_tmp;
				}
			}
		}

		for (int i = 0; i < n; i++){
			cout << team[i].name << "," << team[i].sum << endl;
		}

		if (n != 0){
			cout << endl;
		}
	}

	return (0);
}

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;
		if(c++)cout << endl;
		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++: /*
	AOJ_0124: League Match Score Sheet
*/
#include	<iostream>
#include	<string>
#include	<algorithm>
#include	<vector>

using namespace std;

class Teams {
private:
	int num;
	string name;
	int score;
public:
	Teams(){
		score = 0;
	}
	Teams(int n, string c, int s){
		num = n;
		name = c;
		score = s;
	}
	void showTeams(void) {
		cout << name << ',' << score << endl;
	}
	bool operator<(const Teams& another) const {
		if (score != another.score) { return score > another.score; }
		return num < another.num;
	}
};

int main(void) {
	int N, c_win, c_draw, c_lose, c_score;
	string c_name;
	bool isDo = false;

	while (1) {
		vector<Teams> T;

		cin >> N;
		if (N == 0) { break; }
		if (isDo == true) { cout << endl; }

		for (int i = 0; i < N; i++) {
			cin >> c_name >> c_win >> c_lose >> c_draw;
			c_score = c_win * 3 + c_draw;
			T.push_back( Teams(i, c_name, c_score) );
		}
		sort(T.begin(), T.end());
		vector<Teams>::iterator it = T.begin();
		while (it != T.end()) {
			it->showTeams();
			it++;
		}
		isDo = true;
	}

	return 0;
}

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

#define	score	first
#define	id		second

using namespace std;

typedef	pair<int,int>	pii;

int main()
{
	int n;

	while(cin>>n,n){
		map<string,pii> mp;
		string name;
		int w,d,l;

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

		vector< pair<pii,string> > v;
		map<string,pii>::iterator it;
		for(it=mp.begin();it!=mp.end();it++){
			v.push_back(make_pair(it->second,it->first));
		}

		sort(v.begin(),v.end(),greater< pair<pii,string> >());

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

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,num=0,score[1000];
    while(1){
        num++;
    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;
    }
        cout<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;
const int N=1e2+10;
void swap(int &a,int &b){
    int temp=a;
    a=b;
    b=temp;
    return ;
}
int main(){
    int n,f[N],a[N],w,l,d;
    bool first=true;
    string c[N];
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        if(first)first=false;
        else printf("\n");
        for(int i=0;i<n;i++){
            cin>>c[i];
            f[i]=i;
            scanf("%d%d%d",&w,&l,&d);
            a[i]=w*3+d;
        }
        for(int i=0;i<n;i++)for(int j=1;j<n;j++)if(a[f[j-1]]<a[f[j]])swap(f[j],f[j-1]);
        for(int i=0;i<n;i++)cout<<c[f[i]]<<","<<a[f[i]]<<endl;
    }
}

C++: #include <iostream>
#include <string>
using namespace std;
struct {string n; int w, l, d, p;} t[10];
int main()
{
	int n, i, j;
	while (cin >> n, n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> t[i].n >> t[i].w >> t[i].l >> t[i].d;
			t[i].p = t[i].w * 3 + t[i].d;
		}
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (t[j].p < t[j+1].p)
					swap(t[j], t[j+1]);
			}
		}
		for (i = 0; i < n; i++)
			cout << t[i].n << "," << t[i].p << endl;
		cout << endl;
	}
}