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>
int main()
{
	int n,win[10],lose[10],draw[10],point[10];
	char name[10][21],b[21];
	while(scanf("%d",&n)!=0){
		for(int i=0;i<n;i++){
			scanf("%s %d %d %d",name[i],&win[i],&lose[i],&draw[i]);
			point[i]=win[i]*3+draw[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(point[i]<point[j]){
					int a=point[i];
					point[i]=point[j];
					point[j]=a;
					strcpy(b,name[i]);
					strcpy(name[i],name[j]);
					strcpy(name[j],b);
				}
			}
		}
		for(int i=0;i<n;i++)
			printf("%s,%d\n",name[i],point[i]);
	}
}

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[10];
int main(void){
	cin>>N;
	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-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;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n, a, b, c;
string s;

vector<string> vs;
vector<P> vi;

bool flag(P i, P j){
	if (i.first == j.first){
		return i.second < j.second;
	}
	else return i.first > j.first;
}

int main(){
	bool f = 0;
	while (cin >> n&&n){
		REP(i, n){
			cin >> s >> a >> b >> c;
			vi.push_back(make_pair(a * 3 + c, i));
			vs.push_back(s);
		}
		sort(ALL(vi), flag);
		if (f)cout << endl;
		REP(i, vi.size()){
			cout << vs[vi[i].second] << "," << vi[i].first << endl;
		}
		f = 1;
		vs.clear();
		vi.clear();
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,b[100],c[100],x,y,z,j,max;
	char a[100][100];
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			b[i]=0; c[i]=0;
		}	
		for(i=0;i<n;i++){
			scanf("%s %d %d %d",a[i],&x,&y,&z);
			b[i]=x*3+z;
		}
		for(i=0;i<n;i++){
			max=-1;
			for(j=0;j<n;j++){
				if(max<b[j]) max=b[j];
			}
			for(j=0;j<n;j++){
				if(max==b[j]){
					printf("%s, %d\n",a[j],b[j]);
					b[j]=-2;
				}
			}	
		}
	}	
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string.h>
#include <string>
#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;
}

C++: #include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,pair<int,string> > P;
int main(void){
  int n,w,l,d,f = 0;
  string t;
  while(cin >> n,n){
    if(f) cout << "\n";
    f = 1;
    vector<P> v;
    for(int i = 0;i < n; i++){
      cin >> t >> w >> l >> d;
      P p;
      p.first = w * 3 + d;
      p.second.first = n - i;
      p.second.second = t;
      v.push_back(p);
    }
    sort(v.begin(),v.end());
    for(int i = n - 1;i >= 0; i--) cout << v[i].second.second << "," << v[i].first << endl;
  }
}

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

typedef pair<int, string> c;
vector<c> V;

bool compare(c x,c y) {
  return x.first<y.first;
}

int main() {
  int N;
  cin >> N;
  while(1) {
    if(N == 0) break;
    for(int i=0;i<N;i++) {
      int win,lose,draw,point;
      string country;
      cin >> country >> win >> lose >> draw;
      point = win * 3 + draw * 1;
      c temp;
      temp.first = point;
      temp.second = country;
      V.push_back(temp);
    }
    stable_sort(V.rbegin(), V.rend(), compare);

    for(int i=0;i<N;i++) {
      cout << V[i].second << "," << V[i].first << endl;
    }
    N=0;
    cin >> N;
    if(N == 0) break;
    else cout << endl;
    V.clear();
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int n,i,win,draw,lose,point[10],tn;
	string str[10],tstr;
	while(cin >> n && n){
		for(i=0;i<n;i++){
			cin >> str[i] >> win >> lose >> draw;
			point[i] = (win*3)+(draw*1);
		}
		for(i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(point[i] < point[j]){
					tstr = str[i];
					str[i] = str[j];
					str[j] = tstr;
					tn = point[i];
					point[i] = point[j];
					point[j] = tn;
				}
			}
		}
		for(i=0;i<n;i++){
			cout << str[i] << "," << point[i] << endl;
			if(i == n-1){
			cout << "\n";
			}
		}
	}
	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];

  while(1){
    cin >> t;
    if(!t)break;

    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;
    cout << endl;
  }
}