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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll w, l, d, n;
  string name;
  bool ch = false;
  while(cin >> n, n) {
    vector<pair<int, string> > result;
    if(ch) cout << endl;
    rep(i, n) {
      cin >> name >> w >> l >> d;
      ll pt = (3 * w + d) * 100 + 99 - i;
      result.pb(make_pair(pt, name));
    }
    sort(result.begin(), result.end());
    reverse(result.begin(), result.end());
    rep(i, n) {
      cout << result[i].second << "," << result[i].first / 100 << endl;
    }
    ch = true;
  }
	return 0;
}

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



using namespace std;

int main(void){
	while(1){
		int a,n;
		string s;
		multimap<int,string,greater<int>> P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert(pair<int, string>(w*3+d,s));
		}
		multimap<int, string,greater<int>>::iterator it =P.begin();
		while( it !=P.end() ){
			cout << (*it).second << "," << (*it).first << endl;
			++it;
		}

	}
	return 0;
}

C++: #include<stdio.h>

int main()
{
	int score[11],win,lose,draw,point[11];
	int n,i,j;
	char str[11][21];
	
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",str[i]);
			scanf("%d%d%d", &win, &lose, &draw);
			score[i]=win*3+draw;
			point[i]=score[i];
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]>point[j]){
					point[10]=point[i];
					point[i]=point[j];
					point[j]=point[10];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(point[i]==score[j]){
					printf("%s,%d\n",str[j],score[j]);
					score[j]=-1;
					break;
				}
			}
		}
		printf("\n");
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct www_t{
  string name;
  int w;
  int l;
  int d;
  int p;
  int num;
};

bool asc(www_t left,www_t right) {
    return left.p == right.p ? left.num < right.num : left.p > right.p;
}

int main(){
  int n;
  scanf ("%d",&n);
  while(n){
    vector<www_t> a(n);
    for(int t=0;t<n;++t){
      cin >> a[t].name >> a[t].w >> a[t].l >> a[t].d;
      a[t].num=t;
      a[t].p=a[t].w*3+a[t].d;
    }
    sort(a.begin(), a.end(),asc);
    for(int t=0;t<n;++t){
      cout << a[t].name << "," << a[t].p << endl;
    }
    scanf ("%d",&n);
    if(n){
      printf("\n");
    }
  }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef struct{
  char name[20];
  int kati;
  int make;
  int hiki;
  int total;
}BU;
int main(){
  BU t[10];
  int flag=0;
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    if(flag==1){
      cout<<endl;
    }
    flag=1;
    for(int i=0;i<n;i++){
      cin>>t[i].name>>t[i].kati>>t[i].make>>t[i].hiki;
      t[i].total=0;
      t[i].total+=t[i].kati*3+t[i].hiki;
    }
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(t[j].total>t[j-1].total){
	  BU tmp=t[j];
	  t[j]=t[j-1];
	  t[j-1]=tmp;
	}
      }
    }
    for(int i=0;i<n;i++){
      cout<<t[i].name<<','<<t[i].total<<endl;
    }
  }
}

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;
　　　　　
		
　　　　　　　　cout<<endl;

	}

	return 0;

}

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

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

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,(float)(w*3+d*1) + 0.1 * (n - i)};
			all[i] = t;
		}
		std::sort(all,all+n,tsort);
		for(int i = 0;i < n;i++){
			std::cout<<all[i].name<<","<<(int)all[i].point<<std::endl;
		}
		std::cout<<std::endl;
	}
}

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

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

using namespace std;

int main()
{
    int n;
    int cnt = 0;

    while (cin >> n) {
        if (!n)
            break;
        if (cnt++)
            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 * 2 + ev, str);
            tourn.push_back(p);
        }
        sort(tourn.rbegin(), tourn.rend());
        
        for (int i = 0; i < tourn.size(); i++)
            cout << tourn[i].second << ',' << tourn[i].first << endl;
    }

    return 0;
}