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 <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int n;
	bool flag = false;

	while( cin >> n , n ){
		vector<int> vc;
		map<int,vector<string> > f;
		if( flag ){
			cout << endl;
		}else{
			flag = true;
		}

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

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

using namespace std;

typedef pair<string, int> P;

bool cp(const P &p1, const P &p2) {
	return p1.second > p2.second;
}

int main() {
	int n; bool f = false;
	while (cin >> n, n) {
		if (f) cout << endl;

		vector<P> v;
		for (int i = 0; i < n; ++i) {
			string str; cin >> str;
			int w, l, d; cin >> w >> l >> d;
			int p = w * 3 + d;

			v.push_back( P(str, p) );
		}
		sort( v.begin(), v.end(), cp );

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

		f = true;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

struct Team{
	string name;
	int n,s;
	bool operator <(const Team t)const{
		if(s==t.s) return n<t.n;
		return s>t.s;
	}
};

int main(){
	Team T[10];
	int N,W,L,D;
	while(cin>>N,N){
		for(int i=0;i<N;i++){
			cin>>T[i].name>>W>>L>>D;
			T[i].n = i; T[i].s = W*3+D;
		}
		sort(T,T+N);
		for(int i=0;i<N;i++){
			cout<<T[i].name;
			printf(",%d\n",T[i].s);
		}
	}
}

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

struct Team{
    string name;
    int id;
    int point;
    bool operator <(const Team& r) const{
        return point == r.point ? id < r.id : point > r.point;
    }
};


int main(){
    vector< Team > v(10);
    string name;
    int n, a, b, c, i;
    while(cin >> n, n){
        for(i = 0; i < n; i++){
            cin >> name >> a >> b >> c;
            v[i].id = i;
            v[i].name = name;
            v[i].point = a * 3 + c;
        }
        sort(v.begin(), v.end());
        for(i = 0; i < n; i++){
            cout << v[i].name << "," << v[i].point << endl;
        }
    }
    return 0;
}

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

//勝敗構造体
typedef struct struct_point
{
	int win;
	int loss;
	int drow;
}S_point;

//データ構造体
typedef struct struct_data
{
	char name[21];
	S_point s_point;
	int point;
}S_data;

int main(void)
{
	//入力数
	int n = 0;
	//交換構造体
	S_data s_tmp;
	S_data *ptr_tmp = &s_tmp;

	S_data s_data[10] = {0};

	bool flag = true;

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			return 0;
		}

		if (flag == true)
		{
			flag = false;
		}
		else
		{
			cout << endl;	
		}

		for (int i = 0; i < n; i++)
		{
			cin >> s_data[i].name >> s_data[i].s_point.win >> s_data[i].s_point.loss >> s_data[i].s_point.drow;
			s_data[i].point = s_data[i].s_point.win * 3 + s_data[i].s_point.drow;
		}

		//ソート
		for (int i = 0; i < n - 1; i++)
		{
			for (int j = i + 1; j < n; j++)
			{
				if (s_data[i].point < s_data[j].point)
				{
					*ptr_tmp = s_data[i];
					s_data[i] = s_data[j];
					s_data[j] = *ptr_tmp;
				}
			}
		}

		for (int i = 0; i < n; i++)
		{
			//cout << s_data[i].name << "," << s_data[i].point << endl;
			cout << s_data[i].name << "," <<s_data[i].point << endl;
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
	char na[10][21],x[21];
	int n,w[10],l[10],d[10],i,j,y;
	while(scanf("%d",&n)!=0){
		for(i=0;i<n;i++){
			scanf("%s %d %d %d",na[i],&w[i],&l[i],&d[i]);
			l[i]=w[i]*3+d[i];
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(l[i]<l[j]){
					y=l[i];  l[i]=l[j];  l[j]=y;
					strcpy(x,na[i]);  strcpy(na[i],na[j]);  strcpy(na[j],x);
				}
			}
		}
		for(i=0;i<n;i++)  printf("%s,%d\n",na[i],l[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<map>
using namespace std;
int main(){
  int n,p=0;
  while(cin>>n,n){
    multimap<int,string,greater<int> >m;
    if(p)cout<<endl;
    p++;
    while(n--){
    string s;
    int a,b,c;  
    cin>>s>>a>>b>>c;
    a=a*3+c;
    m.insert( make_pair(a,s) );
    }
    for(multimap<int,string,greater<int> >::iterator it=m.begin();it!=m.end();it++){
      cout<<(*it).second<<' '<<(*it).first<<endl;
      }
  }
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main(void){
	int n,a,b,c,w[10],i,j,temp,x=0;
	char as[10][21];
	while(1){
		int s[10]={0,1,2,3,4,5,6,7,8,9};
	scanf("%d",&n); //???????????°
		if(n==0)break;
		//if(x>0&&n!=0)cout<<endl;
		 cout<<endl;
	for(i=0;i<n;i++){
		scanf("%s%d%d%d",as[i],&a,&b,&c);
		w[i]=a*3+c;
	}
	for(i=0;i<n;i++){
		for(j=n-1;j>i;j--){
			if(w[i]<w[j]){
				swap(w[i],w[j]);
				swap(s[i],s[j]);
			}
			else if(w[i]==w[j]){
				if(s[i]>s[j]){
					swap(s[i],s[j]);
				}
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s,%d\n",as[s[i]],w[i]);
	}
		x++;
		cout<<endl;
	}
	return 0;
}

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

int main(){
    int n;
    for(int l = 0;;l++){
        cin >> n;
        if(n == 0) break;
        if(l != 0) cout << endl;
        vector<string> s(n);
        vector<pair<int, int> > d;
        for(int i = 0; i < n; i++){
            int a, b, c;
            cin >> s[i] >> a >> b >> c;
            d.push_back(make_pair(3 * a + c, -i));
        }
        sort(d.begin(), d.end());
        reverse(d.begin(), d.end());
        for(int i = 0; i < n; i++){
            cout << s[-d[i].second] << "," << d[i].first << endl;
        }
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        string str[10];
        int num[10];
        for(int i=0,win,lose,draw;i<n;i++){
            cin>>str[i]>>win>>lose>>draw;
            num[i]=win*3+draw;
            str[i]+=',';
        }
        for(int i=0;i<n;i++){
            int ma=0;
            for(int j=0;j<n;j++)if(num[ma]<num[j])ma=j;
            cout<<str[ma]<<num[ma]<<endl;
            num[ma]=-1;
        }
        cout<<endl<<endl;
    }
}