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++: /*
	2013 08 01
	Miyagi Technical High School
	J1 JK club Taiki F Watanabe
*/

#include<stdio.h>

typedef struct INFO_TEAM
{
	// チーム名
	char name[21];
	
	// 勝の数
	int win;
	// 負の数
	int lose;
	// 引分の数
	int draw;
	// 成績
	int points;
}INFO;

int main(void)
{
	int i = 0, j = 0, num = 0;
	INFO tmp;
	INFO team[10];
	
	while(1)
	{

		scanf("%d", &num);

		if(num == 0)
		{
			break;
		}

		for(i = 0; i < num; i++)
		{
			scanf("%s %d %d %d", &team[i].name, &team[i].win, &team[i].lose, &team[i].draw);

			team[i].points = 0;

			team[i].points += team[i].win * 3;
			team[i].points += team[i].draw;
		}

		putchar('\n');

		for(i = 0; i < num; i++)
		{
			for(j = 0; j < num; j++)
			{
				if(team[i].points > team[j].points)
				{
					tmp = team[i];
					team[i] = team[j];
					team[j] = tmp;
				}
			}
		}

		for(i = 0; i < num; i++)
		{
			printf("%s,%d\n", team[i].name, team[i].points);
		}

		putchar('\n');
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
long p[10];
bool cm(const long l, const long r){return p[l]>p[r];}
int main(){
long n,i,w,l,d,id[10],f=0;
string s[10];
while(cin>>n){
if(n==0)break;
if(f>0)cout<<endl;f=1;
for(i=0;i<n;i++)p[i]=0;
for(i=0;i<n;i++){
cin>>s[i]>>w>>l>>d;
p[i]+=3*w+d;
id[i]=i;
}
sort(id,id+n,cm);
for(i=0;i<n;i++){
cout<<s[id[i]]<<","<<p[id[i]]<<endl;
}
}
return 0;
}

C++: //Name: League Match Score Sheet
//Level: 1
//Category: やるだけ
//Note: 

/**
 * 入力時に勝ち点を計算し、ソートする。
 *
 * オーダーは O(N log N)。
 */
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;
    if(!first) cout << endl;

    vector<pair<int,string>> vs;
    for(int i = 0; i < N; ++i) {
        string t;
        int w, l, e;
        cin >> t >> w >> l >> e;
        vs.emplace_back(w*3 + e, t);
    }
    stable_sort(begin(vs), end(vs), [](const pair<int,string> &a, const pair<int,string> &b){return a.first > b.first;});
    for (const auto &t : vs) {
        cout << t.second << "," << t.first << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) first = false;
    return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<int, string>>ps;
		for (int i = 0; i < N; ++i) {
			string st; int a, b, c; cin >> st >> a >> b >> c;
			int score = a * 3 + c;
			ps.emplace_back(score*100-i+99, st);
		}
		sort(ps.begin(), ps.end(),greater<pair<int,string>>());
		for (auto p : ps) {
			cout << p.second << "," << p.first/100 << endl;
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;
typedef pair<string,int> P; 

int main(){
  int n;
  bool first = true;
  while(cin >> n && n){
    if(!first)cout << endl;
    string s;
    first = false;  
  vector<P> vec;
    int a,b,c;
    for(int i=0;i<n;i++){
    cin >> s >> a >> b >> c;
    vec.push_back(P(s,a*3+b*0+c*1));
    }

    stable_sort(vec.rbegin(),vec.rend());
    //reverse(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
      cout << vec[i].F << "," << vec[i].S << endl;
    }
 
  }
  return 0;
}

C++: #include <iostream>
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int N;
typedef pair<int, int> P;
vector<string> mp;
vector<P> wp;

int comp(P a, P b) {
	return a.second > b.second;
}

int main() {
	bool first = true;
	while (true) {
		cin >> N;
		if (N == 0) {return 0;}
		if (!first) {
			cout << endl;
		}
		first = false;
		mp.clear();
		wp.clear();
		for (int i = 0; i < N; i++) {
			string country;
			cin >> country;
			int w, d, l;
			cin >> w >> l >> d;
			mp.push_back(country);
			wp.push_back(P(i, 3 * w + d));
		}
		stable_sort(wp.begin(), wp.end(), comp);
		for (int i = 0; i < wp.size(); i++) {
			cout << mp[wp[i].first] << "," << wp[i].second << endl;
		}
	}
}

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

class Team
{
  public:
    Team(string& name, int win, int draw, int index);

    bool operator<(const Team& other) const;
    void Show();

  private:
    string m_name;
    int m_score;
    int m_index;
};

Team::Team(string& name, int win, int draw, int index) :
  m_name(name), m_index(index)
{
  m_score = win * 3 + draw * 1;
}

bool Team::operator<(const Team& other) const
{
  return m_score == other.m_score ? m_index > other.m_index : m_score < other.m_score;
}

void Team::Show()
{
  cout << m_name << "," << m_score << endl;
}

int main(void)
{
  bool flag = false;
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    if (flag) cout << endl;
    flag = true;
    
    vector<Team> teams;
    for (int i = 0; i < n; ++i)
    {
      string name;
      int win, lose, draw;
      cin >> name >> win >> lose >> draw;
      Team buf_team(name, win, draw, i);
      teams.push_back(buf_team);
    }
    sort(teams.rbegin(), teams.rend());
    for (auto team : teams)
    {
      team.Show();
    }
  }
  return 0;
}

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

using namespace std;

int main()
{
	vector<pair<int, pair<int, string> > > team;
	int n, pt[10][3];
	string str[10];

	while(1){
		cin >> n;

		if(n == 0)    break;

		for(int i = 0; i < n; i++)
			cin >> str[i] >> pt[i][0] >> pt[i][1] >> pt[i][2];

		for(int i = 0; i < n; i++)
			team.push_back(make_pair(((pt[i][0] * -3) - pt[i][2]), make_pair(i, str[i])));

		sort(team.begin(), team.end());

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

	return 0;
}