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>
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];
      }
    }
    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.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){

					char fout[20];
					strcpy_s(fout, teamdata[i].name);
					strcpy_s(teamdata[i].name, teamdata[i + 1].name);
					strcpy_s(teamdata[i + 1].name, fout);

					int gout;
					gout = teamdata[i].score;
					teamdata[i].score = teamdata[i + 1].score;
					teamdata[i + 1].score = gout;

				}

			}


		}

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


	}

	return 0;

}

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

using namespace std;

int main(void){
  int n, a, b, c;
  string s;
  vector<pair<int, pair<int, string> > > v;

  while(cin >> n, n){
    v.clear();

    for(int i=0; i<n; i++){
      cin >> s >> a >> b >> c;
      v.push_back(make_pair((a * 3) + c, make_pair(n - i, s)));
    }
    sort(v.begin(), v.end(), greater<pair<int, pair<int, string> > >());

    for(int i=0; i<n; i++){
      cout << v[i].second.second << "," << v[i].first << endl;
    }
    cout << endl;
  }

  return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n){
        vector<pii>v;
        vector<string>amausa;
        rep(i,n){
            int gotiusa=0;
            string rabit; cin>>rabit;
            amausa.push_back(rabit);
            int kokoa,rize,tino; cin>>kokoa>>rize>>tino;
            gotiusa+=kokoa*3+tino;
            v.push_back(pii(gotiusa,-i));
        }
        sort(all(v),greater<pii>());
        rep(i,n)cout<<amausa[-1*v[i].second]<<","<<v[i].first<<endl;
        cout<<endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>


using namespace std;

struct country_point{
    string country;
    int num;
    int point;
};

bool country_point_compare(country_point l, country_point r){
    if(l.point>r.point)return true;
    if(l.point<r.point)return false;
    if(l.num<r.num)return true;
    return false;
}

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        country_point all_country[10];
        for(int i=0; i<n; i++){
            string c;
            cin>>c;
            all_country[i].country = c;
            int win, loss, drow;
            cin>>win;
            all_country[i].point=win*3;
            cin>>loss;
            cin>>drow;
            all_country[i].point+=drow;
            all_country[i].num = i;
        }
        
        sort(all_country, all_country+n, country_point_compare);
        
        for(int i=0; i<n; i++){
            cout<<all_country[i].country<<","<<all_country[i].point<<endl;
        }
        cout<<endl;
    }
    
}

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.begin(), tourn.end());
        reverse(tourn.begin(), tourn.end());
        
        for (int i = 0; i < tourn.size(); i++)
            cout << tourn[i].second << ',' << tourn[i].first << endl;
        nl = true;
    }

    return 0;
}

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


int main(void){
	int n;
	bool o = 0 ;
	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;
				}
			}
		if(o)cout<<endl;
		o = true;
		for(int i = 0 ; i < n ; i ++)
			cout<<name[rank[i]]<<","<<sum[rank[i]]<<endl;
	}
}