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 <vector>
#include <algorithm>

using namespace std;

typedef pair<int, string> T;

int main()
{
    int n;
    bool fst = true;
    while(cin >> n && n) {
        if(!fst) {
            fst = false;
        } else {
            cout << endl;
        }
        vector<T> vt;
        string name;
        int a,b,c;
        while(n--) {
            cin >> name >> a >> b >> c;
            vt.push_back(T(a * 3 + c, name));
        }
        
        sort(vt.begin(), vt.end());
        for(int i = vt.size() - 1; i >= 0; i--) {
            cout << vt[i].second << "," << vt[i].first << endl;
        }
    }
}

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

int main(){
  string str[11],str2;
  int N;
  int po[11][4],sc[11],T;

  while(1){
  cin>>N;
  if(N==0) break;

  for(int i=0;i<N;i++){
    cin>>str[i];
    for(int j=0;j<3;j++){
      cin>>po[i][j];
    }
  }
  cout<<endl;

  for(int i=0;i<N;i++){
    sc[i]=po[i][0]*3+po[i][2];
  }
  
  for(int i=0;i<N-1;i++){
    for(int j=N-1;j>i;j--){
      if(sc[j-1]<sc[j]){
	T=sc[j];
	sc[j]=sc[j-1];
	sc[j-1]=T;
	str2=str[j-1];
	str[j-1]=str[j];
	str[j]=str2;
      }
    }
  }

for(int i=0;i<N;i++){
  cout<<str[i]<<","<<sc[i]<<endl;
 }
  }
return 0;
}

C++: #include<iostream>
#include<string>
#include<unordered_set>
#include<vector>
using namespace std;
typedef unordered_set<string> US;
typedef vector<string> VS;

int main() {
	int n;
	int lp = 0;
	while (cin >> n, n) {
		VS v[30];
		if (lp != 0)cout << endl;

		for (int i = 0;i < n;i++) {
			string s;
			int a, b, c;
			cin >> s >> a >> b >> c;
			int p = 3 * a + c;
			v[p].push_back(s);
		}

		for (int i = 29;i > -1;i--) {
			for (auto itr = v[i].begin();itr != v[i].end();itr++) {
				cout << *itr << ',' << i << endl;
			}
		}
		lp++;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    bool first = true;

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, string> > score(n);
        for(int i=0; i<n; ++i){
            int a, b, c;
            cin >> score[i].second >> a >> b >> c;
            score[i].first = 3 * a + c;
        }

        stable_sort(score.rbegin(), score.rend());
        if(first)
            first = false;
        else
            cout << endl;
        for(int i=0; i<n; ++i){
            cout << score[i].second << ',' << score[i].first << endl;
        }
    }
}

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


int main(void){
	int n;
	while(cin>>n,n){
		string name[n];
		int sum[n],point;
		int rank[n];
		for(int i = 0 ; i < n ; i ++){
			cin>>name[i];
			cin>>point; //win
			sum[i]=point*3;
			cin>>point;	//lose;
			cin>>point; //drow
			sum[i]+=point;
			rank[i]=i;			
		}
		for(int i = 0 ; i < n ; i ++)
			for(int j = 0 ; j < n ; j ++){
				if(sum[rank[i]]>sum[rank[j]]){
					int t = rank[i];
					rank[i] = rank[j];
					rank[j] = t;
				}
			}
		for(int i = 0 ; i < n ; i ++)
			cout<<name[rank[i]]<<","<<sum[rank[i]]<<endl;
		
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a;
	bool k = false;
	while (cin >> a&&a != 0) {
		if (k)
			cout << endl;
		string s[10];
		int b[10];
		int g[10];
		for(int i = 0; i < a; i++) {
			string m;
			int c, d, e;
			cin >> m >> c >> d >> e;
			s[i] = m;
			int f = c * 3 + e;
			b[i] = f;
			g[i] = f;
		}
		sort(g, g + a);
		for (int i = a-1; i >=0; i--) {
			int h = g[i];
			for (int j = 0; j < a; j++) {
				if (b[j] == h) {
					cout << s[j] << "," << h << endl;
					break;
				}
			}
		}
		k = true;
	}
}

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

#define	score	first
#define	id		second

using namespace std;

typedef	pair<int,int>	pii;

bool cmp(const pii& a,const pii& b)
{
	if(a.score>b.score)	return true;
	if(a.score==b.score && a.id<b.id)	return true;
	return false;
}

int main()
{
	int n;

	for(int k=0;cin>>n,n;k++){
		if(k>0)	cout<<endl;

		vector<pii> scvec;
		map<int,string> namemap;

		for(int i=0;i<n;i++){
			string name;
			int w,l,d;
			cin>>name>>w>>l>>d;
			scvec.push_back(make_pair(3*w+d,i));
			namemap[i]=name;
		}

		sort(scvec.begin(),scvec.end(),cmp);

		for(int i=0;i<scvec.size();i++){
			cout<<namemap[scvec[i].id]<<","<<scvec[i].score<<endl;
		}
	}

	return 0;
}

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<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
        for(;;){

        int n,q=0;
        cin>>n;
        if(n==0)break;
        int w[10],l[10],d[10];
        int p[10];

        char team[10][20];


        for(int i=0;i<n;i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            p[i]=w[i]*3+d[i];
        }
        for(int i=3*n;i>=0;i--){
            for(int j=0;j<n;j++){
                if(p[j]==i){
                    cout<<team[j]<<","<<p[j]<<endl;
                    q++;
                }
            }

        }


        }
	return 0;
}

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

typedef pair<int,int> P;
typedef pair<P,string> PP;

int main(void)
{
	PP team[10] = {};
	int n;
	int win,lost,draw;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> team[i].second;
		cin >> win >> lost >> draw;
		team[i].first.first = win*3+draw;
		team[i].first.second= 10-i;
	}
	sort( team, team+10 );

	for(int i = 9; 10-i <= n; i--)
		cout << team[i].second << ',' << team[i].first.first << endl;


	return 0;
}