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.h>
int main()
{
	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]);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	multimap<int,string,greater<int> > data;
	bool ok = false;
	while(1){
		data.clear();
		int n;
		cin >> n;
		if(n==0) break;
		string tmp;
		int a,b,c;
		if(ok) cout << endl; 
		if(ok==false) ok = true;
		REP(i,n){
			cin >> tmp >> a >> b >> c;
			data.insert(multimap<int,string>::value_type(a*3+c,tmp));
		}
		for(multimap<int,string>::iterator it = data.begin();it != data.end(); it++){
			cout<<(*it).second<<","<<(*it).first<<endl;
		}
		
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;
pair<int,int> p[10];

int main()
{
  int i,n;
  char name[10][25]={};
  int w,l,d;
  bool time=false;
  while(1){
    cin>>n;
    if(n==0)break;
    if(time)
      cout<<endl;
    rep(i,n){
      scanf("%s %d %d %d",name[i],&w,&l,&d);
      p[i].first=-1*(w*3+d);
      p[i].second=i;
    }
    sort(p,p+n);
    
    rep(i,n)
      printf("%s,%d\n",name[p[i].second],-1*(p[i].first));

    time=true;
  }

}

C++: #include<stdio.h>
int main()
{
 int score[11],win,lose,draw,point[11];
 int n,i,j,k;
 char str[11][21];
 
 for(k=0;;k++){
  scanf("%d",&n);
  if(n==0)break;
  if(k!=0)puts("");
  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;
    }
   }
  }
 }
 return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
struct Team
{
	string team;
	int num,point;
};
bool comp(Team a,Team b)
{
	if(a.point!=b.point)return a.point>b.point;
	return a.num < b.num;
}
int main()
{
	bool first=true;
	while(1)
	{
		if(!first)cout << endl;
		else first=false;
		int n;
		scanf("%d",&n);
		if(n==0)break;
		vector<Team> vec;
		for(int i=0;i<n;i++)
		{
			string team;
			int win,lose,tie;
			cin >> team >> win >> lose >> tie;
			int point=win*3+tie;
			Team a;
			a.team=team;
			a.num=i;
			a.point=point;
			vec.pb(a);
		}
		sort(vec.begin(),vec.end(),comp);
		for(int i=0;i<vec.size();i++)
		{
			cout << vec[i].team << ',' << vec[i].point << endl;
		}
	}
	return 0;
}

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

using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

int main(void){
	while(1){
		int a,n;
		string s;
		vector<pair<int,string>> P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.push_back(make_pair(w*3+d,s));
		}
		stable_sort(P.begin(),P.end(),cmp);
		for(a=0;a<n;a++){
			cout << P[a].second << "," << P[a].first << endl; 
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std ;

main(){
	string t[21] , tmp ;
	int p[21] , tmp2 ;
	int n , a , b , c ;
	
	while( cin >> n , n ){
		map<string,int> x ;
		for( int i=0 ; i<n ; i++ ){
			cin >> t[i] >> a >> b >> c ;
			p[i] = a*3 + c ;
			x[t[i]] = i ;
		}
		
		for( int i=0 ; i<n ; i++ ){
			for( int j=i+1 ; j<n ; j++ ){
				if( p[i] < p[j] || p[i] == p[j] && x[t[i]] > x[t[j]] ){
					tmp = t[i] ;
					t[i] = t[j] ;
					t[j] = tmp ;
					
					tmp2 = p[i] ;
					p[i] = p[j] ;
					p[j] = tmp2 ;
				}
			}
		}
		
		for( int i=0 ; i<n ; i++ ) cout << t[i] << ',' << p[i] << endl ;
		cout << endl ;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
        for(;;){

        int n,q=0;
        cin>>n;
        if(n==0)break;
        int w[20],l[20],d[20];
        int p[20];

        char team[20][40];


        for(int i=0;i<n;i++){
            scanf("%s%d%d%d",team[i],&w[i],&l[i],&d[i]);
            p[i]=w[i]*3+d[i];
        }
        for(int i=3*n;i>=0;i--){
            for(int j=0;j<n;j++){
                if(p[j]==i){
                    cout<<team[j]<<","<<p[j]<<endl;
                    q++;
                }
            }

        }

        cout<<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,flg;
	flg=1;
	scanf("%d",&n);
	while(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);
				}
			}
		}
		if(flg==0)  printf("\n");
		for(i=0;i<n;i++)  printf("%s,%d\n",na[i],l[i]);
		flg=0;
		scanf(" %d",&n);
	}
	return 0;
}