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.h>
using namespace std;
 
struct data{
 
    char name[20];
    int win;
    int lose;
    int draw;
    int score;
 
};
 
int main(){
 
    int teamamo;
 
    while (true){
 
        cin >> teamamo;
 
        if (teamamo == 0)
            break;
 
        data teamdata[10];
         
 
        for (int i = 0; i<teamamo; i++)
            cin >> teamdata[i].name >> teamdata[i].win >> teamdata[i].lose >> teamdata[i].draw;
 
        for (int i = 0; i<teamamo; i++)
            teamdata[i].score = teamdata[i].win * 3 + teamdata[i].draw;
 
 
        for (int j = 0; j < teamamo - 1; j++){
            for (int i = 0; i < teamamo - 1; i++){
 
                if (teamdata[i].score < teamdata[i + 1].score){
 
                    data t = teamdata[i];
                    teamdata[i] = teamdata[i + 1];
                    teamdata[i + 1] = t;
 
                }
 
            }
 
 
        }
 
        for (int i = 0; i<teamamo; i++)
            cout << teamdata[i].name << "," << teamdata[i].score << endl<<endl;
　　　　　
         
　　　　　　　　
 
    }
 
    return 0;
 
}

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

typedef struct{
	string name;
	int score;
}Team;

int main(void){
	int n;
	bool firstFlg = true;
	
	while(cin>>n && n){
		if(!firstFlg) cout<<endl;
		else firstFlg = false;
	
		Team t[n];
		for(int i=0;i<n;i++){
			int win,lose,draw;
			
			cin>>t[i].name>>win>>lose>>draw;
			t[i].score = win*3 + draw;
		}
		
		for(int i=0;i<n-1;i++){
			for(int j=0;j<n-1;j++){
				if(t[j].score < t[j+1].score){
					Team tmp = t[j];
					t[j] = t[j+1];
					t[j+1] = tmp;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			cout<<t[i].name<<","<<t[i].score<<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++: /*************************************/
/*     ??\?????\?????\?????\??¬???????????±???006???????????????2?????? */
/*          coded by Y.Suganuma      */
/*************************************/
#include <stdio.h>

int main()
{
	int i1, i2, k, n, p[10], p1, p2, p3;
	char name[10][21];
					// ??\???????????\?????????????£???????
	scanf("%d", &n);
					// ??\???????????\?????????????£?????????????????????????????????????????????????
	for (i1 = 0; i1 < n; i1++) {
		scanf("%s %d %d %d", name[i1], &p1, &p2, &p3);
		p[i1] = 3 * p1 + p3;
	}
					// ????????????
	for (i1 = 0; i1 < n; i1++) {
		k = -1;
		for (i2 = 0; i2 < n; i2++) {
			if (p[i2] >= 0) {
				if (k < 0 || p[i2] > p[k])
					k = i2;
			}
		}
		printf("%s,%d\n", name[k], p[k]);
		p[k] = -1;
	}

	return 0;
}

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

class Team{
public:
	int id,score;
	string name;
	Team(){}
	Team(int _id,int _score,string _name){
		id = _id;
		score = _score;
		name = _name;
	}
	bool operator<(const Team t)const{
		if(score == t.score) return id < t.id;
		return score > t.score;
	}
};

int main(void){
	int n;
	bool first = true;

	while(cin>>n,n){
		if(first) first = false;
		else cout<<endl;

		Team t[n];
		for(int i=0;i<n;i++){
			string name;
			int a,b,c;
			cin>>name>>a>>b>>c;
			t[i] = Team(i,3*a+c,name);
		}
		sort(t,t+n);
		for(int i=0;i<n;i++){
			cout<<t[i].name<<","<<t[i].score<<endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int n;
	int flg = 0;
	while(1){
        cin >> n;
        if(n == 0) break;
        if(flg == 1) cout << endl;
        flg = 1;
        char cou[30][20];
        int kati[20],make[20],hiki[20];
        int p[20];

        for(int i = 0; i < n; i++){
            cin >> cou[i] >> kati[i] >> make[i] >> hiki[i];
            p[i] = 3 * kati[i] + hiki[i];
        }
        for(int i = n * n; i >= 0; i--){
            for(int j = 0; j < n; j++){
                if(p[j] == i) cout << cou[j] << "," << p[j] << endl;
            }
        }
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main()
{
	int n,win[10],lose[10],draw[10],point[10];
	char name[10][21],b[21];
	while(scanf("%d",&n)!=0){
		for(int i=0;i<n;i++){
			scanf("%s %d %d %d",name[i],&win[i],&lose[i],&draw[i]);
			point[i]=win[i]*3+draw[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(point[i]<point[j]){
					int a=point[i];
					point[i]=point[j];
					point[j]=a;
					strcpy(b,name[i]);
					strcpy(name[i],name[j]);
					strcpy(name[j],b);
				}
			}
		}
		for(int i=0;i<n;i++)
			printf("%s,%d\n",name[i],point[i]);
	}
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pint pair<string, int>
bool desc(pint a, pint b) {
	return a.second > b.second;
}
int main() {
	int n;
	while(cin >> n, n) {
		vector<pint> v;
		rep(i,n) {
			string t;
			int tmp, s = 0;
			cin >> t;
			cin >> tmp;
			s += tmp * 3;
			cin >> tmp;
			cin >> tmp;
			s += tmp;
			v.push_back(make_pair(t,s));
		}
		sort(v.begin(), v.end(), desc);
		for(pint p : v) {
			cout << p.first << "," << p.second << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100],d[100],f[100],g[100],h,i,j,q;
	char z[100][100],x[100];
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++){
			g[i]=0;
			scanf("%s %d %d %d",z[i],&s[i],&d[i],&f[i]);
			g[i]=s[i]*3+f[i];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]<g[j]){
					h=g[i];
					g[i]=g[j];
					g[j]=h;
					strcpy(x, z[i]);
					strcpy(z[i], z[j]);
					strcpy(z[j], x);
					q=s[i];
					s[i]=s[j];
					s[j]=q;
				}
			}
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]==g[j]){
					if(s[i]<s[j]){
						q=s[i];
						s[i]=s[j];
						s[j]=q;
						h=g[i];
						g[i]=g[j];
						g[j]=h;
						strcpy(x, z[i]);
						strcpy(z[i], z[j]);
						strcpy(z[j], x);
					}
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%s,%d\n",z[i],g[i]);
		}
	}
	return 0;
}