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.h>
using namespace std;

struct data{

	char name[20];
	int win;
	int lose;
	int draw;
	int score;

};

int main(){

	int teamamo;

	while (true){

		cin >> teamamo;

		if (teamamo == 0)
			break;

		data teamdata[10];
		

		for (int i = 0; i<teamamo; i++)
			cin >> teamdata[i].name >> teamdata[i].win >> teamdata[i].lose >> teamdata[i].draw;

		for (int i = 0; i<teamamo; i++)
			teamdata[i].score = teamdata[i].win * 3 + teamdata[i].draw;


		for (int j = 0; j < teamamo - 1; j++){
			for (int i = 0; i < teamamo - 1; i++){

				if (teamdata[i].score < teamdata[i + 1].score){

					data t = teamdata[i];
					teamdata[i] = teamdata[i + 1];
					teamdata[i + 1] = t;

				}

			}


		}

		for (int i = 0; i<teamamo; i++)
			cout << teamdata[i].name << "," << teamdata[i].score << endl;


	}

	return 0;

}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int x, kazu, w, l, d, ten[11], dai, kazu2, ans[55][11],kaisuu[55];
	string kuni[55][11], taihi[11];
	kazu = 0;
	while (1) {
		dai = 0;
		cin >> x;
		if (x == 0) {
			goto a;
		}
		kazu = kazu + 1;
		for (int i = 1; i <= x; i++) {
			cin >> taihi[i] >> w >> l >> d;
			ten[i] = w * 3 + d;
			if (dai < ten[i]) {
				dai = ten[i];
			}
		}
		kazu2 = 0;
		for (int z = dai; z >= 0; z--) {
			kaisuu[kazu] = x;
			for (int i = 1; i <= x; i++) {
				if (ten[i] == z) {
					kazu2 = kazu2 + 1;
					kuni[kazu][kazu2] = taihi[i];
					ans[kazu][kazu2] = ten[i];
				}
			}
		}
	}
a:;
	for (int i = 1; i <= kazu; i++) {
		for (int z = 1; z <= kaisuu[i]; z++) {
			cout << kuni[i][z] << "," << ans[i][z] << endl;
		}
		if (i != kazu) {
			cout << endl;
		}
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    int f = 0;
    while(scanf("%d",&n),n){
        if(f == 1)printf("\n");
        char team[100][100] = {{0}};
        int w[110],d[110],l[110];
        int to[110][10] = {0};

        //in
        for(int i = 0;i < n; i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            to[i][0] = (w[i]*3)+d[i];
            to[i][1] = w[i];
        }
        //out
        for(int i = 0;i < n; i++){
            for(int j = 0;j < n; j++){
                if(to[i][0] > to[j][0]){
                    swap(to[i][0],to[j][0]);
                    swap(team[i],team[j]);
                }
                else if(to[i][0] == to[j][0] && i != 0){
                    if(to[i][1] > to[j][1]){
                        swap(to[i][0],to[j][0]);
                        swap(team[i],team[j]);
                    }
                }
            }
        }
        for(int i = 0;i < n; i++)printf("%s,%d\n",team[i],to[i][0]);
        f = 1;
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100],d[100],f[100],g[100],h,i,j,q;
	char z[100][100],x[100];
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++){
			g[i]=0;
			scanf("%s %d %d %d",z[i],&s[i],&d[i],&f[i]);
			g[i]=s[i]*3+f[i];
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]<g[j]){
					h=g[i];
					g[i]=g[j];
					g[j]=h;
					strcpy(x, z[i]);
					strcpy(z[i], z[j]);
					strcpy(z[j], x);
				}
			}
		}
		for(i=0;i<a;i++){
			printf("%s,%d\n",z[i],g[i]);
		}
		printf("\n");
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

typedef pair<int,string> mypair;

int main(void){

int n, k, m, h;
mypair ch[10];

	while(cin >>n){
		if(n==0 || cin.eof()) break;
		rep(i,n){
			cin >> ch[i].second;
			cin >> k >> m >> h;
			ch[i].first = (k *3 + h *1) * 100 + 50- i;
		}
		sort(ch, ch+n, greater<mypair>());
		rep(i,n) cout << ch[i].second << "," << (int)(ch[i].first/100) << endl;
		cout << endl;
	}
	return 0;
	
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

struct Data{
	string name;
	int w, l, d,sum,id;
};

int main()
{
	int n;
	
	while (cin >> n, n) {

		vector<Data> s(n);
		for (int i = 0; i < n; i++) {
			s[i].id = i;
			cin >> s[i].name >> s[i].w >> s[i].l >> s[i].d;
			s[i].sum = s[i].w * 3 + s[i].d;
		}

		for (int i = 0; i < n-1; i++) 
			for (int j = i+1; j < n; j++) 
				if (s[i].sum < s[j].sum)swap(s[i], s[j]);
		
		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (i == j)continue;
				if (s[i].sum == s[j].sum) {
					if (s[i].id > s[j].id)swap(s[i], s[j]);
				}
			}
		}

		for (int i = 0; i < n; i++)
			cout << s[i].name << "," << s[i].sum << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef pair<int,string> P;

int main(){
    int n,w=-1,l,d;
    string s;
    vector<P> v;

    while(cin>>n,n){
        if(w!=-1) cout<<endl;
        for(int i=0;i<n;i++){
            cin>>s>>w>>l>>d;
            cin.ignore();
            v.push_back(P(3*w+d,s));
        }

        stable_sort(v.begin(),v.end(),greater<P>());

        for(auto p:v){
            cout<<p.second<<","<<p.first<<endl;
        }

        v.clear();
    }

    return 0;
}

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

int main(){
	int n;
	while( cin >> n , n ){
		vector<int> vc;
		map<int,vector<string> > f;

		for(int i=0 ; i < n ; i++ ){
			string name;
			int a,b,c;

			cin >> name >> a >> b >> c;
			int p = -(a*3 + c);
			if( count(vc.begin(),vc.end(),p) == 0 ){
				vc.push_back( p );
			}
			f[p].push_back( name );
		}
		sort( vc.begin() , vc.end() );
		for(int i=0 ; i < vc.size() ; i++ ){
			for(int j=0 ; j < f[vc[i]].size() ; j++ ){
				cout << f[vc[i]][j] << "," << -vc[i] << endl;
			}
		}
	}
}