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 <algorithm>
#include <map>
#include <vector>
#include <string>

using namespace std;

bool compare(const pair<int, int> &p, const pair<int, int> &q) 
{
    return (p.first != q.first) ? p.first > q.first : p.second < q.second;
}

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

    while (cin >> n) {
        if (!n)
            break;
        if (nl)
            cout << endl;

        vector< pair<int, int> > tourn;
        vector<string> name;

        for (int i = 0; i < n; i++) {
            int win, los, ev;
            string str;
        
            cin >> str >> win >> los >> ev;

            tourn.push_back(pair<int, int>(win * 3 + ev, i));
            name.push_back(str);
        }
        sort(tourn.begin(), tourn.end(), compare);
        
        for (int i = 0; i < tourn.size(); i++)
            cout << name[tourn[i].second] << ',' << tourn[i].first << endl;
        nl = true;
    }

    return 0;
}

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;



}
}

C++: #include<cstdio>
 using namespace std;
typedef struct{
    char name[30];
    int ten;
}team;
 
int main(){
    int n,i,j,k,m,h,f;
    team soccer[10],t;
    f=1;
    while(~scanf("%d",&m)){
        if(m==0)break;
        if(f!=1)printf("\n");
        f=2;
        for(i=0;i<m;i++){
            scanf(" %s %d %d %d ",soccer[i].name,&k,&n,&h);
            soccer[i].ten=3*k+h;
        }
         
        for(i=0;i<m;i++){
            for(j=0;j<m-1;j++){
                if(soccer[j].ten<soccer[j+1].ten){
                    t=soccer[j];
                    soccer[j]=soccer[j+1];
                    soccer[j+1]=t;
                }
            }
        }
        for(i=0;i<m;i++){
            printf("%s,%d\n",soccer[i].name,soccer[i].ten);
        }
    }
    return 0;
}

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 <string>

using namespace std;
typedef pair<string, int> P;
void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> data(n);
		int temp[3];
		for(int i = 0; i < n; ++i)
		{
			cin >> data[i].first >> temp[0] >> temp[1] >> temp[2];
			data[i].second = temp[0] * 3 + temp[2];
		}
		
		for(int i = 0; i < n; ++i)
		{
			for(int j = n - 1; j > i; --j)
			{
				if(data[j].second > data[j - 1].second)
				{
					P a = data[j];
					data[j] = data[j - 1];
					data[j - 1] = a;
				}
			}
		}
		for(int i = 0; i < n; ++i)
		{
			cout << data[i].first << "," << data[i].second << endl;
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

typedef struct{
  string name;
  int sum;
}TEAM;

int main(){
  int rev = 0;
  int num;
  while(cin >> num && num){
    if(rev) cout << endl;
    rev++;
    int win, lose, draw;
    TEAM team[num];
    for(int i = 0; i < num; i++){
      cin >> team[i].name >> win >> lose >> draw;
      team[i].sum = win*3 + draw;
    }
    for(int i = 0; i < num-1; i++){
      for(int j = 0; j < num-i-1; j++){
	if(team[j].sum < team[j+1].sum){
	  TEAM tmp = team[j];
	  team[j] = team[j+1];
	  team[j+1] = tmp;
	}
      }
    }
    for(int i = 0; i < num; i++){
      cout << team[i].name <<"," << team[i].sum<<endl;
    }
  }
  return 0;
}

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


using namespace std;

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

int main(void){
	bool b=false;
	while(1){
		int a,n;
		string s;
		multimap<int, string, greater<int> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int a,b,n,f=0;
  string s;
  for(;cin>>n,n;){
    if(f)cout<<endl;
    vector<pair<int,string> >v;
    for(f=0;f<n;v.push_back(make_pair(a*3+b,s)),f++)
      cin>>s>>a>>b>>b;
    for(a=0;a<n;a++)
      for(b=0;b<n-1;b++)
        if(v[b].first<v[b+1].first)iter_swap(v.begin()+b,v.begin()+b+1);
    for(a=0;a<n;a++)
      cout<<v[a].second<<','<<v[a].first<<endl;
    f=1;
  }
}

C++: #include<bits/stdc++.h>

using namespace std ;

struct s
{
	int p ;
	string tm ;
} ;

int main()
{
	int n ;
	while( cin >> n ,n )
	{
		int p1 ;
		s st[ n ] ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> st[ i ].tm >> st[ i ].p >> p1 >> p1 ;
			st[ i ].p = st[ i ].p * 3 + p1 ;
		}

		for( int i = 0 ; i < n ; i++ )
		{
			for( int j = i + 1 ; j < n ; j++ )
			{
				if( st[ i ].p < st[ j ].p )
					swap( st[ i ] ,st[ j ] ) ;
			}
		}

		for( int i = 0 ; i < n ; i++ )
			cout << st[ i ].tm << "," << st[ i ].p << endl ;

	}
	return 0 ;
}