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>
#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;
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef struct{
  string team;
  int win;
  int lose;
  int drow;
  int point;
}much;
  
int main(){
  int a=0;
  while(1){
    much x[11],smp;
    int n;    
    if(a){
      cout << endl;
    }
    cin >> n;
    if(n == 0)break;
    for(int i=0;i<n;i++){
      cin >> x[i].team >> x[i].win >> x[i].lose >> x[i].drow;
    }
    for(int i=0;i<n;i++){
      x[i].point = x[i].win*3 + x[i].drow;
    }
    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
	if(x[i].point < x[j].point){
	  smp = x[i];
	  x[i] = x[j];
	  x[j] = smp;
	}
      }
    }
    for(int i=0;i<n;i++){
      cout << x[i].team << "," << x[i].point << endl;;
    }
    a=1;
  }
}

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

struct Team {
  int score, id;
  string name;
  bool operator < (const Team &t) const {
    if(score != t.score) return score > t.score;
    return id < t.id;
  }
};

int n;
Team t[10];

int main() {
  while(cin >> n && n) {
    for(int i = 0; i < n; ++i) {
      int a, b, c;
      cin >> t[i].name >> a >> b >> c;
      t[i].score = a*3 + c;
      t[i].id = i;
    }
    sort(t, t+n);
    static int tc = 0;
    if(tc++) cout << endl;
    for(int i = 0; i < n; ++i) {
      cout << t[i].name << "," << t[i].score << endl;
    }
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair

using namespace std;

struct Team
{
	int point;
	int num;
	string name;

	bool operator< (const Team& t)const
	{
		return point == t.point ?  num < t.num : point < t.point;
 	}

};

int main()
{
	int n;
	bool fisrt = true;
	while(cin >> n && n)
	{

		if(fisrt)
		{
			fisrt = false;
		}
		else
		{
			cout << endl;
		}
		priority_queue<Team> q;
		string s;
		int a,b,c;
		rep(i,n)
		{
			cin >> s >> a >> b >> c;
			Team t;
			t.point = 3*a + c;
			t.num = n-i;
			t.name = s;
			
			q.push(t);
		}

		rep(i,n)
		{
			cout << q.top().name << "," << q.top().point << endl;
			q.pop();
			
		}
		
	}
	return 0;
}

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

struct team{
  int point;
  int mun;
  string name;
};

class LessAn {
public:
    bool operator()(const team& a, const team& b)
    {
      if(a.point==b.point)
        return a.mun < b.mun;
      return a.point > b.point;
    }
};




int main()
{
  long int n;
  for(;cin>>n,n;)
    {
      vector<team> t;      
      for(int i=1;n--;i++)
      {
	string tt;
	int x,y,z;
	team a;
	cin>>tt>>x>>y>>z;
	a.point=x*3+z;
	a.name=tt;
	a.mun=i;
	t.push_back(a);
      }
      sort(t.begin(), t.end(),LessAn());
	for(int i=0;i<t.size();i++)
	  {
	    cout<<t[i].name<<","<<t[i].point<<endl;
	  }
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	int n;
	while ( cin >> n && n )
	{
		vector <string> team_names(n);
		vector <int> points(n,0);
		vector <int> id(n,0);
		for ( int i = 0; i < n; i++ )
		{
			id[i] = i;
			cin >> team_names[i];
			int point;
			cin >> point;
			points[i] += point * 3;
			cin >> point;
			cin >> point;
			points[i] += point;
		}

		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i + 1; j < n; j++ )
			{
				if ( points[i] < points[j] )
				{
					swap( points[i], points[j] );
					swap( team_names[i], team_names[j] );
					swap( id[i], id[j] );
				}
				else if ( points[i] == points[j] )
				{
					if ( id[i] > id[j] )
					{
						swap( points[i], points[j] );
						swap( team_names[i], team_names[j] );
						swap( id[i], id[j] );
					}
				}
			}
		}

		for ( int i = 0; i < n; i++ )
		{
			cout << team_names[i] << ',' << points[i] << endl;
		}

	}

	return 0;
}

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

int main() {
  int n, W, L, E;
  bool flag = false;
  string T;
  vector<int> vc;
  map<int,vector<string> > res;  
  
  while(cin >> n, n) {
    if(flag) cout << endl;
    else flag = true;
    
    for(int i = 0 ; i < n ; i++) {
      cin >> T >> W >> L >> E;
      int P = -(W*3 + E);
      if(count(vc.begin(), vc.end(), P) == 0) {
	vc.push_back(P);
      }
      res[P].push_back(T);
    }
    sort(vc.begin() , vc.end());
    for(int i = 0 ; i < vc.size() ; i++)
      for(int j = 0 ; j < res[vc[i]].size() ; j++)
	cout << res[vc[i]][j] << ',' << -vc[i] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <strstream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;

int main(){
	int n;
	int w,l,d=0;
	while(cin>>n && n)
	{
		if(d++)puts("");
		multimap< int,string,greater<int> >m;
		for(int i=0; i<n; i++)
		{
			string t;
			cin>>t>>w>>l>>d;
			m.insert( make_pair( w*3+d , t ) );
		}
		for(multimap< int,string,greater<int> >::iterator it=m.begin(); it != m.end(); it++)
			cout<< (*it).second << ',' << (*it).first << endl;
	}
	return 0;
}

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

int N,sum[10],sum2[10];
struct DATA{
	string country;
	int win,lose,drow,sum,flag; 
};
DATA data[11];
int main(void){
	while(1){
		for(int i=0;i<N;i++){data[i]=data[11];sum[i]=0;sum2[i]=0;}
		cin>>N;
		if(N==0){break;}
		for(int i=0;i<N;i++){
			cin>>data[i].country>>data[i].win>>data[i].lose>>data[i].drow;
			data[i].sum=data[i].win*3+data[i].drow;
			sum[i]=data[i].sum;
		}
		sort(sum,sum+N);
		for(int i=0;i<N;i++){sum2[i]=sum[N-1-i];}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(sum2[i]==data[j].sum && data[j].flag==0){
					cout<<data[j].country<<","<<data[j].sum<<endl;
					data[j].flag=1;
					break;
				}
			}
		}
	}
	return 0;
}