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<map>
#include<string>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    string s[11];
    map<string, int> score;
    int win[11], lose[11], drow[11];
    for(int i=0; i<n; i++){
      cin >> s[i] >> win[i] >> lose[i] >> drow[i];
      score[s[i]] = win[i]*3+drow[i]*1;
    }

    for(int i=0; i<n; i++){
      int M_score=0, winer=0;
      for(int j=0; j<n; j++){

	if(M_score < score[s[j]]){
	  M_score=score[s[j]];
	  winer=j;
	}

	else if(M_score == score[s[j]]){
	  if(win[winer] < win[j]){
	    M_score=score[s[j]];
	    winer=j;
	  }
	  
	  else if(win[winer]==win[j]){
	    if(drow[winer] < drow[j]){
	      M_score=score[s[j]];
	      winer=j;
	    }

	    else if(drow[winer]==drow[j]){
	      if(lose[winer] < lose[j]){
		M_score=score[s[j]];
		winer=j;
	      }
	    }

	  }
	  
	}
	
      }
      cout << s[winer] << "," << M_score << endl;
      score[s[winer]] = -1;
    }
    cout << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <iterator>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int main(void){
	while(1){
		int a,n;
		string s;
		multimap<int,string,greater<int>> P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert(pair<int, string>(w*3+d,s));
		}
		multimap<int, string,greater<int>>::iterator it =P.begin();
		while( it !=P.end() ){
			cout << (*it).second << "," << (*it).first << endl;
			++it;
		}

	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Result{
	string name;
	int score;
	Result(){}
	Result(string n,int s):name(n),score(s){}
	bool operator>(const Result& r)const{return score>r.score;}
};

int main()
{
	bool first=true;
	for(int n;cin>>n,n;){
		if(!first)
			cout<<endl;
		first=false;
		
		vector<Result> rs(n);
		rep(i,n){
			int a,b,c;
			cin>>rs[i].name>>a>>b>>c;
			rs[i].score=a*3+c;
		}
		stable_sort(allof(rs),greater<Result>());
		rep(i,n)
			cout<<rs[i].name<<","<<rs[i].score<<endl;
	}
	
	return 0;
}

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

using namespace std;

class Team{
public:
	string name;
	int win;
	int lose;
	int draw;
	int point;

};
bool operator<( const Team& rhs, const Team& lhs ){
	return ( rhs.point < lhs.point );
}
bool operator>( const Team& rhs, const Team& lhs ){
	return ( rhs.point > lhs.point );
}
int main(int argc, char const* argv[])
{
	int num;
	Team team[10];

	while( cin >> num && num != 0 ){
		for( int i = 0;i < num;i++ ){
			cin >> team[i].name >> team[i].win >> team[i].lose >> team[i].draw;
			team[i].point = team[i].win * 3 + team[i].draw;
		}
		stable_sort( team, team + num, greater<Team>() );
		for( int i = 0;i < num;i++ ) cout << team[i].name << "," << team[i].point << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int main(){
  int n;
  while(cin>>n,n){
    vector<pair<int,string>> P;
    int w,l,d;
    string s;
    rep(i,n){
      cin>>s>>w>>l>>d;
      P.pb(mp(3*w+d,s));
    }
    sort(all(P));
    for(int i=P.size()-1;i>=0;i--){
        cout<<P[i].sec<<','<<P[i].fir<<endl;
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
 
typedef pair<int, string> P;
 
bool compare(P a, P b)
{
    return a.first > b.first;
}
 
int main()
{
    int n, a, b, c, t = 0;
    string str;
     
    while (cin >> n, n) {
        if (t) puts("");
        t++;
        vector<P> v;
        for (int i = 0; i < n; i++) {
            cin >> str >> a >> b >> c;
            int p = a * 3 + c;
            v.push_back(P(p, str));
        }
        stable_sort(v.begin(), v.end(), compare);
        for (int i = 0; i < n; i++) {
            cout << v[i].second << "," << v[i].first << endl;
        }
    }
    return 0;
}

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

class Team {
public:
  string name;
  int win;
  int id;
  Team(string name="", int win=0, int id=0) : name(name), win(win), id(id) {}
  bool operator <(const Team &t) const {
    if(win == t.win) return id > t.id;
    else             return win < t.win;
  }
};

int main() {
  bool first = true;
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    Team tm[n];
    for(int i = 0; i < n; i++) {
      int a, b, c;
      cin >> tm[i].name >> a >> b >> c;
      tm[i].win = a*3 + b*0 + c*1;
      tm[i].id = i;
    }
    sort(&tm[0], &tm[n-1]+1);

    if(!first) {
      cout << endl;
    } else {
      first = false;
    }
    for(int i = n-1; i >= 0; i--) {
      cout << tm[i].name << ',' << tm[i].win << endl;
    }

  }
  return 0;
}