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>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, string> T;

int main()
{
    int n;
    bool fst = true;
    while(cin >> n && n) {
        if(!fst) {
            fst = false;
        } else {
            cout << endl;
        }
        vector<T> vt;
        string name;
        int a,b,c;
        while(n--) {
            cin >> name >> a >> b >> c;
            vt.push_back(T(a * 3 + c, name));
        }
        
        stable_sort(vt.begin(), vt.end());
        for(int i = vt.size() - 1; i >= 0; i--) {
            cout << vt[i].second << "," << vt[i].first << endl;
        }
    }
}

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; c[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>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

struct DATA{
  string Team;
  int Score;
};

bool compare(const DATA&, const DATA&);

int main(){
  int i, n, win, draw, lose, count=0;
  string s;
  DATA one;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;
    else if(count != 0) cout << endl;

    for(i=0; i<n; ++i){
      cin >> s >> win >> lose >> draw;
      one.Team = s;
      one.Score = win * 3 + draw;
      data.push_back(one);
    }

    sort(data.begin(), data.end(), compare);

    for(i=0; i<data.size(); ++i)
      cout << data[i].Team << "," << data[i].Score << endl;

    data.clear();
    ++count;
  }

  return 0;
}

bool compare(const DATA& x, const DATA& y){
  return x.Score > y.Score;
}

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){
	bool b=false;
	while(1){
		int a,n;
		string s;
		vector< pair<int,string> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		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 <string>
using namespace std;
struct {string n; int w, l, d, p;} t[10], x;
int main()
{
	int n, i, j, b=0;
	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;
		}
		if (b < 0) cout << endl;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (t[j].p < t[j+1].p)
				{
					x = t[j];
					t[j] = t[j+1];
					t[j+1] = x;
				}
			}
		}
		for (i = 0; i < n; i++)
			cout << t[i].n << "," << t[i].p << endl;
		b--;
	}
}

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

struct Team{
	string name;
	int score;
	bool operator>(const Team &t) const { return (score > t.score); }
};

int main(void){
	bool bFirst = true;
	while( true ){
		int n;
		vector<Team> vTeam;

		cin >> n;
		if( n == 0 )
			break;

		if( !bFirst )
			cout << '\n';
		else
			bFirst = false;

		for(int i = 0 ; i < n; ++i){
			Team tmp;
			int win, lose, draw;

			cin >> tmp.name >> win >> lose >> draw;
			tmp.score = win * 3 + lose * 0 + draw * 1;
			vTeam.push_back( tmp );
		}
		stable_sort( vTeam.begin(), vTeam.end(), greater<Team>() );
		
		for(unsigned int i = 0; i < vTeam.size(); ++i)
			cout << vTeam[i].name << ',' << vTeam[i].score << '\n';
	}
	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){
	int b=0;
	while(1){
		int a,n;
		string s;
		vector< pair<int,string> > P;
		int w,d,l;
		if(b++)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++: #include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};

int main()
{
	int n;
	bool fis = true;
	while (cin >> n && n)
	{
		if (fis)
		{
			fis = false;
		}
		else
		{
			cout << endl;
		}
		vector< pair <int, string> > a;
		for (int i = 0; i < n; i++)
		{
			int p = 0;
			string name;
			cin >> name;
			p += in() * 3; in();
			p += in();

			a.push_back(pair<int, string>(p, name));
		}

		for (int l = 0; l <= n; l++)
		{
			for (int i = 1; i < a.size(); i++)
			{
				if (a[i].first > a[i - 1].first)swap(a[i], a[i - 1]);
			}
		}

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