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>
#include<iostream>
using namespace std;

struct TA{
string name;
int po;
int rr;};


int main(){
int n;
struct TA N[11]; 
while(1){
scanf("%d",&n);if(n==0)break;
for(int i=0;i<n;i++)
{cin>>N[i].name;
int a,b,c;
cin>>a>>b>>c;
N[i].po=a*3+c*1;
N[i].rr=i;
}
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(N[j].po>N[j-1].po){struct TA T=N[j];N[j]=N[j-1];N[j-1]=T;}

for(int i=0;i<n;i++)
cout<<N[i].name<<","<<N[i].po<<endl;

cout<<endl;


}
return 0;
}

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

int main(){
    int n;
    int cnt = 0;
    while(cin >> n, n){
        if(cnt != 0) cout << endl;
        cnt++;
        string s[10];
        vector<int> d, e;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> s[i] >> a >> b >> c;
            d.push_back(3 * a + c);
        }
        e = d;
        sort(d.begin(), d.end());
        reverse(d.begin(), d.end());
        bool f[10] = {0};
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(d[i] == e[j] && f[j] == false){
                    f[j] = true;
                    cout << s[j] << "," << d[i] << endl;
                    break;
                }
            }
        }
    }
}

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

int main(){
  int n;
  while(cin >> n){
    if(n == 0) break;
    multimap<int, string> ranking;
    for(int i = 0; i < n; i++){
      string  country;
      int win, lose, draw;
      cin >> country >> win >> lose >> draw;
      int point = win * 3 + lose * 0 + draw * 1;
      ranking.insert(make_pair(point, country));
    }

    for(multimap<int, string>::reverse_iterator ite = ranking.rbegin(); ite != ranking.rend(); ite++){
      cout << (*ite).second << ',' << (*ite).first << endl;
    }
  }

  return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void)
{
	int team,win,lose,draw,point[10];
	char name[10][21],b[21];
	while(1){
		scanf("%d",&team);
		if(team==0)
			break;
		for(int i=0;i<team;i++){
			scanf("%s %d %d %d",name[i],&win,&lose,&draw);
			point[i]=win*3+draw;
		}
		for(int i=0;i<team-1;i++){
			for(int j=i+1;j<team;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<team;i++)
			printf("%s,%d\n",name[i],point[i]);
		printf("\n");
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j,k,x,n;
	int win,lose,drow;
	char kuni[10][21];
	int tokuten[10];
	while(1) {
		cin>>n;if(n==0)break;
		for(i=0;i<n;i++) {
			cin>>kuni[i]>>win>>lose>>drow;
			tokuten[i]=win*3+drow;
		}
		for(i=0;i<n-1;i++) {
			for(j=0;j<n;j++) {
				if(tokuten[i]<tokuten[j]) {
					swap(tokuten[i],tokuten[j]);
					swap(kuni[i],kuni[j]);
				}
			}
		}
		for(i=n-1;i>=0;i--) {
			cout<<kuni[i]<<","<<tokuten[i]<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
struct team{
	std::string name;
	int point;
	int n;
};

bool tsort(const team& a,const team& b){
	if(a.point - b.point){
		return a.point > b.point;
	}
	return a.n < b.n;
}

int main(){
	int n;
	while(std::cin>>n,n){
		team all[10];
		for(int i = 0;i < n;i++){
			std::string name;
			int w,d,l;
			std::cin>>name>>w>>l>>d;
			team t = {name,w*3+d,i};
			all[i] = t;
		}
		std::cout<<std::endl;
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<all[i].point<<std::endl;
		}
		std::cout<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<string>s(n);
	vector<int>t(n);
	rep(i,n){
	  int a,b,c;
	  cin>>s[i]>>a>>b>>c;
	  t[i]=3*a+c;
	}
	rep(i,n){
	  rep(j,n-i-1){
	    if(t[j]<t[j+1]){
		  swap(t[j],t[j+1]);
		  swap(s[j],s[j+1]);
		}
      }
	}
	rep(i,n)cout<<s[i]<<','<<t[i]<<endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#define F first
#define S second
using namespace std;
typedef pair<int,string> pii;
int main(){
    int n;
    while(cin>>n,n){
        string str;
        int W,L,D;
        priority_queue<pii>Q;
        while(n--){
            cin>>str>>W>>L>>D;
            Q.push(pii(W*3+D,str));
        }
        while(!Q.empty()){
            pii p=Q.top();Q.pop();
            cout<<p.S<<","<<p.F<<endl;
        }
    }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        char team[11][21] = {{0}};
        int w[11],d[11],l[11];
        int to[11][2] = {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]){
                    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]);
    }
    return 0;
}

C++: #include<iostream>
#include<complex>
#include<cstring>
#include<sstream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<vector>
#include<string>
#include<deque>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<functional>
#include<algorithm>
#define rep(i,k) for(int i=0;i<k;i++)
using namespace std;
typedef pair<int,string> P;
int main(){
	int n,x,y,z;
	priority_queue<P> tab;
	string s;
	while(cin>>n,n){
		rep(i,n){
			cin>>s>>x>>y>>z;
			tab.push(P(x*3+z,s));
		}
		while(!tab.empty()){
			P q=tab.top();
			cout<<q.second<<','<<q.first<<endl;
			tab.pop();
		}
		cout<<endl;
	}
	return 0;
}