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

struct Team{
	string name;
	int win;
	int lose;
	int draw;
	int point;
};

void sort( Team* teams, int n )
{
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j < n - 1; ++j ){
			if( teams[ j ].point < teams[ j + 1 ].point ){
				Team t = teams[ j ];
				teams[ j ] = teams[ j + 1 ];
				teams[ j + 1 ] = t;
			}
		}
	}
}

int main()
{
	int teamQuantity;
	bool first = true;

	while( cin >> teamQuantity ){
		if( teamQuantity == 0 ){
			break;
		}
		Team* teams = new Team[ teamQuantity ];
		for( int i = 0; i < teamQuantity; ++i ){
			cin >> teams[ i ].name >> teams[ i ].win >> teams[ i ].lose >> teams[ i ].draw;
			teams[ i ].point = teams[ i ].win * 3 + teams[ i ].draw;
		}
		sort( teams, teamQuantity );

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

		for( int i = 0; i < teamQuantity; ++i ){
			cout << teams[ i ].name << "," << teams[ i ].point << endl;
		}
		delete[] teams;
	}
	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,l=0;
	char z[100][100],x[100];
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
		if(l!=0)	printf("\n");
		l++;
		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);
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%s,%d\n",z[i],g[i]);
		}

	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	bool flag = true;
	int n,i,win,draw,lose,point[10],tn;
	string str[10],tstr;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			cin >> str[i] >> win >> lose >> draw;
			point[i] = (win*3)+(draw*1);
		}
		if(flag == false) cout << "\n";
		for(i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(point[i] < point[j]){
					tstr = str[i];
					str[i] = str[j];
					str[j] = tstr;
					tn = point[i];
					point[i] = point[j];
					point[j] = tn;
				}
			}
		}
		for(i=0;i<n;i++){
			cout << str[i] << "," << point[i] << endl;
		}
		flag = false;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
    int n, f=0;
    while (cin>>n) {
        if (!n) break;
        if (f) cout<<endl;
        else f=1;
        vector<int> m;
        map<int, vector<string> > f;
        for (int i=0; i<n; i++) {
            string name; cin>>name;
            int a,b,c; cin>>a>>b>>c;
            int p=-(a*3+c);
            if (count(m.begin(), m.end(), p)==0) m.push_back(p);
            f[p].push_back(name);
        }
        sort(m.begin(),m.end());
        for (int i=0; i<m.size(); i++) {
            for (int j=0; j<f[m[i]].size(); j++) {
                cout<<f[m[i]][j]<<","<<-m[i]<<endl;
            }
        }
    }
}

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;
		cin >> n;
		if(n==0)break;else cout << endl;
		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++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    bool first = true;

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<pair<int, int>, string> > score(n);
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> score[i].second >> a >> b >> c;
            score[i].first.first = 3 * a + c;
            score[i].first.second = n-i;
        }

        sort(score.rbegin(), score.rend());
        if(first)
            first = false;
        else
            cout << endl;
        for(int i=0; i<n; ++i){
            cout << score[i].second << ',' << score[i].first.first << endl;
        }
    }
}

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

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

int main(void)
{

	int n;


	while(cin >> n,n){

	int win,lost,draw;
	PP team[10] = {};
	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= 10-i;
	}
	sort( team, team+10 );

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

		cout << endl;
	}


	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string a[10];
int p[10];
int main(){
	int n,b,z,c;
	bool first=true;
	while(true){
	cin>>n;
	if(n==0)break;
	if(!first)cout<<endl;
	first=false;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b>>z>>c;
		p[i]=b*3+c*1;
	}
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(p[j]>p[j-1]){
				string tmps=a[j];
				a[j]=a[j-1];
				a[j-1]=tmps;
				int tmp=p[j];
				p[j]=p[j-1];
				p[j-1]=tmp;
			}
		}
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<","<<p[i]<<endl;
	}
	return 0;
}