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<algorithm>
using namespace std;
int main(){
    string name[1000],nmemo;
    int n,a,b,c,num=0,score[1000];
    while(1){
        num++;
    cin>>n;
        if(n==0){
            break;
        }
    for(int i=0;i<n;i++){
        cin>>name[i]>>a>>b>>c;
        score[i]=a*3+c;
    }
    int max=-10000,count=0,j=0,s;bool bo=false;
        cout<<endl;
    while(1){
        if(count==n){
            break;
        }
        for(int i=0;i<n;i++){
            if(score[i]>max){
                max=score[i];
                s=i;
            }
        }
        cout<<name[s]<<","<<score[s]<<endl;
        count++;
        score[s]=-10;
        max=-10000;
    }
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int n,w,l,d;
string name[15];
pair<int,pair<int,string> > data[15];

int main(){
  bool ok=false;
  while(cin>>n){
    if(n==0)break;
    if(ok)cout<<endl;
    else ok=true;
    
    rep(i,n){
      cin>>name[i]>>w>>l>>d;
      data[i].first=w*3+d;
      data[i].second.first=n-i;
      data[i].second.second=name[i];
    }

    sort(data,data+n);reverse(data,data+n);
    
    rep(i,n){
      cout<<data[i].second.second<<","<<data[i].first<<endl;
    }
  }
}

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

struct data{
	
	string name;
	int w;
	int l;
	int e;
	int t;
	static bool s  (const data& x,const data& y){
        return x.t>y.t;
    }
};

int main(){
	
	int n;
	while(cin>>n,n!=0){
		vector<data> m(n);
		for(int i=0;i<n;i++){
			cin>>m[i].name>>m[i].w>>m[i].l>>m[i].e;
			m[i].t=m[i].w*3+m[i].e;
		}
		sort(m.begin(),m.end(),data::s);
		for(int i=0;i<n;i++)
			cout<<m[i].name<<","<<m[i].t<<endl;
		cout<<endl;
	}
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class C{
  public:
    string s;
    int i, a, b, c;
    C(){}
    C(string _s, int _i, int _a, int _b, int _c) { s = _s; i = _i; a = _a; b = _b; c = _c; }
    bool operator < (const C &_) const {
      int x = a * 3 + c, y = _.a * 3 + _.c;
      return (x != y ? x > y : i < _.i);
    }
};

int main() {
  int N;
  bool f = false;
  while(cin >>N && N){
    if(f) cout <<endl;
    f = true;
    vector<C> v(N);
    REP(i, N){
      cin >>v[i].s >>v[i].a >>v[i].b >>v[i].c;
      v[i].i = i;
    }
    SORT(v);
    REP(i, N) cout <<v[i].s <<"," <<v[i].a * 3 + v[i].c <<endl;
  }


  return 0;
}

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

int main() {
	vector<map<double,string>>t(0);
	while (1) {
		int k;
		cin >> k;
		if (k == 0)break;	
			map<double, string>s;
			auto c = 0.01;
			for (int b = 0; b < k; b++) {
				string d; double e, f, g;
				cin >> d >> e >> f >> g;
				s.insert(pair<double, string>((e * 3 + f * 0 + g * 1 + (1 - c)), d));
				c += 0.01;
			}
			t.push_back(s);
	}
	for (int u = 0; u < t.size(); u++) {
		auto y = t[u].end(); y--;
		for (;; y--) {
			cout << y->second << "," <<(int) y->first << endl;
			if (y == t[u].begin())break;
		}
		if (t.size() - 1 != u)cout << endl;
	}
}

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

int main(){

	int n, max_pt, pt[10], win, lose, drow, cnt;
	string str[10];

	cnt = 0;
	while(cin >> n){
		if(n == 0) break;
		if(cnt != 0) cout << endl;
		max_pt = 0;
		for(int i=0; i<n; i++){
			win = 0;
			lose = 0;
			drow = 0;
			cin >> str[i] >> win >> lose >> drow;
			pt[i] = win * 3 + drow;
			max_pt = max(max_pt, pt[i]);
		}
	
		for(int i=max_pt; i>=0; i--){
			for(int j=0; j<n; j++){
				if(pt[j] == i) cout << str[j] << "," << pt[j] << endl;
			}
		}
		cnt++;
	}

	return 0;

}

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

typedef pair<int, string> P;
set<P> team;

int main(void){
  int n, k = 0;
  while(cin >> n, n){
    if(k != 0) cout << endl;
    for(int i = 0; i < n; i++){
      string tname;
      int w, l, d;
      cin >> tname >> w >> l >> d;
      pair<int, string> t;
      t.first = w * 3 + d;  t.second = tname;
      team.insert(t);
    }
    set<P>::reverse_iterator it;
    for(it = team.rbegin(); it != team.rend(); it++){
      cout << (*it).second << "," << (*it).first << endl;
    }
    team.clear();
    k++;
  }
  return 0;
}

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

using namespace std;

int main()
{
    bool nl = false;
    int n;

    while (cin >> n) {
        if (!n)
            break;
        if (nl)
            cout << endl;

        vector< pair<int, string> > tourn;

        for (int i = 0; i < n; i++) {
            int win, los, ev;
            string str;
        
            cin >> str >> win >> los >> ev;
            pair<int, string> p(win * 3 + ev, str);
            tourn.push_back(p);
        }
        stable_sort(tourn.rbegin(), tourn.rend());
        
        for (int i = 0; i < tourn.size(); i++)
            cout << tourn[i].second << ',' << tourn[i].first << endl;
        nl = true;
    }

    return 0;
}