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++: /*
	AOJ_0124: League Match Score Sheet
*/
#include	<iostream>
#include	<string>
#include	<algorithm>
#include	<vector>

using namespace std;

class Teams {
private:
	int num;
	string name;
	int score;
public:
	Teams(){
		score = 0;
	}
	Teams(int n, string c, int s){
		num = n;
		name = c;
		score = s;
	}
	void showTeams(void) {
		cout << name << ',' << score << endl;
	}
	bool operator<(const Teams& another) const {
		if (score != another.score) { return score > another.score; }
		return num < another.num;
	}
};

int main(void) {
	int N, c_win, c_draw, c_lose, c_score;
	string c_name;
	while (1) {
		vector<Teams> T;

		cin >> N;
		if (N == 0) { break; }

		for (int i = 0; i < N; i++) {
			cin >> c_name >> c_win >> c_lose >> c_draw;
			c_score = c_win * 3 + c_draw;
			T.push_back( Teams(i, c_name, c_score) );
		}
		sort(T.begin(), T.end());
		vector<Teams>::iterator it = T.begin();
		while (it != T.end()) {
			it->showTeams();
			it++;
		}
		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));
    }

    sort(vec.begin(),vec.end());
    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 <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

struct team{
	string name;
	int score;
	int num;
	team(string n, int s, int nu):name(n), score(s), num(nu){}
	bool operator<(const team &r)const{
		if(score == r.score) return num > r.num;
		return score < r.score;
	}
};

int main(){
	int n;
	int dataset = 0;
	while(cin >> n, n){
		if(dataset++)cout << endl;
		vector<team> v;
		rep(i, n){
			string name;
			int w, l, d;
			cin >> name >> w >> l >> d;
			v.push_back(team(name, w*3+d, i));
		}
		sort(rev(v));
		rep(i, n){
			cout << v[i].name << ',' << v[i].score << endl; 
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
struct date{
    char cou[30];
    int kati;
    int make;
    int hiki;
    int ten;
    int num;
};
int main()
{
    int flg = 0;
	while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        if(flg == 1) cout << endl;
        flg = 1;
	    date aoj[20];
        for(int i = 0; i < n; i++){
            cin >> aoj[i].cou >> aoj[i].kati >> aoj[i].make >> aoj[i].hiki;
            aoj[i].kati *= 3;
            aoj[i].make *= 0;
            aoj[i].num = i;
            aoj[i].ten = aoj[i].kati + aoj[i].make + aoj[i].hiki;
        }
        for(int i = 0; i < n; i++){
            for(int j = i; j < n; j++){
                if(aoj[i].ten < aoj[j].ten) swap(aoj[i],aoj[j]);
            }
        }

        for(int i = 0; i < n; i++){
            cout << aoj[i].cou << "," << aoj[i].ten << endl;
        }
	}
	return 0;
}

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

int main(){
  int t,w,l,d,s[10],r[10];
  string n[10];
  bool use[10],f = false;

  while(1){
    cin >> t;
    if(!t)break;
    if(f)cout << endl;
    f = true;

    for(int i=0;i<t;i++){
      cin >> n[i] >> w >> l >> d;
      s[i] = w*3 + d;
    }

    for(int i=0;i<t;i++)use[i] = false;
    
    for(int i=0;i<t;i++){
      int m = -1,pos = -1;
      for(int j=0;j<t;j++){
	if(!use[j]){
	  if(m<s[j]){
	    m = s[j];
	    pos = j;
	  }
	}
      }
      r[i] = pos;
      use[pos] = true;
    }

    for(int i=0;i<t;i++)cout << n[r[i]] << "," << s[r[i]] << endl;
  }
}

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];
	bool flag = true;

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

		if(flag)    flag = false;
		else		cout << endl;

		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])));

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

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

	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	char team[10][21],temp[21];
	int knit,n,win[10],lose[10],drow[10],wpt[10],i,j,nanka=0;
	
	for(;;){
		scanf("%d",&n);
		if(n==0) break;
		if(nanka==1) puts("");
		nanka=0;
		for(i=0;i<n;i++){
			scanf("%s%d%d%d",&team[i],&win[i],&lose[i],&drow[i]);
			wpt[i] = win[i] * 3 + drow[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(wpt[i]>wpt[j]){
					knit=wpt[j];
					wpt[j]=wpt[i];
					wpt[i]=knit;
					strcpy(temp,team[j]);
					strcpy(team[j],team[i]);
					strcpy(team[i],temp);
				}
			}
		}
		
		for(i=0;i<n;i++){
			printf("%s,%d\n",team[i],wpt[i]);
		}
		nanka=1;
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string.h>
#include <functional>
using namespace std;
int main()
{
    pair<int,pair<int,string>> team[10];
	int n;
	bool first=true;
	while(cin>>n&&n){
		if(!first)cout<<endl;
		for(int i=0;i<n;i++){
			int k,m,h;
			cin>>team[i].second.second>>k>>m>>h;
			team[i].first=k*3+h;
			team[i].second.first=-i;
		}
		sort(team,team+n,greater<pair<int,pair<int,string>>>());
		for(int i=0;i<n;i++){
			cout<<team[i].second.second<<","<<team[i].first<<endl;
		}
		first=false;
	}
    return 0;
}