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];  
	bool ty=true;
	while(1){ scanf("%d",&n);
	if(n==0)break; for(int i=0;i<n;i++) 
	if(ty==false)cout<<endl;
	ty=false;
	
	{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;         
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    while (true) {
        int n; cin >> n; if (n == 0) break;
        vector<pair<pair<int, int>, string> > v;
        for (int i = 0; i < n; ++i) {
            string t;
            int a, b, c;
            cin >> t >> a >> b >> c;
            v.pb(mp(mp(3*a+c, -i), t));
        }
        sort(v.rbegin(), v.rend());
        for (int i = 0; i < n; ++i)
            cout << v[i].second << "," << v[i].first.first << endl;
        cout << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  bool f = false;
  while(cin>>n){
    if(n==0) break;
    if(f)cout<<endl;
    else f=true;
    vector<pair<PII,string> > data;
    REP(i,n){
      string team;
      int win,tmp;
      cin>>team;
      cin>>tmp;
      win=tmp*3;
      cin>>tmp;
      cin>>tmp;
      win+=tmp;
      data.push_back(pair<PII,string>(PII(-win,i),team));
    }
    sort(data.begin(),data.end());
    REP(i,n){
      printf("%s,%d\n",data[i].second.c_str(),-data[i].first.first);
    }
  }


  return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
typedef    pair<int,pair<int,string> >    P;
const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int main(){
	string team;
	vector<P> data;

	int w,l,d;
	int c =0;
	while(cin>>n,n){
		if(c!=0){
			cout <<endl;
		}
		data.clear();
		for(int i =0;i <n;i++){
			cin>>team>>w>>l>>d;
			int sum =w*3+d*1;
			data.push_back(P(sum,mp(-i,team)));
		}
		sort(data.begin(),data.end(),greater<P>());
		for(int i =0;i <data.size();i++){
			string out =data[i].second.second;
			int score =data[i].first;
			cout <<out<<","<<score<<endl;
		}
		c++;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define F first
#define S second


using namespace std;
typedef pair<string,int> P; 

int main(){
  int n;
  bool first = true;
  while(cin >> n && n){
    if(!first)cout << endl;
    string s;
    first = false;  
  vector<P> vec;
    int a,b,c;
    for(int i=0;i<n;i++){
    cin >> s >> a >> b >> c;
    vec.push_back(P(s,a*3+b*0+c*1));
    }

    sort(vec.rbegin(),vec.rend());
    //reverse(vec.begin(),vec.end());
    for(int i=0;i<n;i++){
      cout << vec[i].F << "," << vec[i].S << endl;
    }
 
  }
  return 0;
}

C++: ok

C++: #include <iostream>
using namespace std;
struct po {
  string str;
  int score;
};

int main() {


int flg = 0;
  while(1) {
    
    int n;
    cin >> n;
    if(n == 0) break;

    po team[11];
    for(int i=0;i<n;i++) {
      int a,b,c;
      cin >> team[i].str >> a >> b >> c;
      team[i].score = a*3+c;
    }

    for(int i=0;i<n;i++) {
      for(int j=n-1;j>i;j--) {
	if(team[j].score > team[j-1].score) {
	  po t = team[j];
	  team[j] = team[j-1];
	  team[j-1] = t;
	}
      }
    }

    if(flg == 1) cout << endl;
    for(int i=0;i<n;i++) 
      cout << team[i].str<<","<<team[i].score<<endl;

    flg = 1;

  }

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

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

void solve(int n){
  string tm[10];
  vector< pair<int,int> > scr;    
  int a,b,c;

  scr.resize(n);
  for(int i=0;i<n;i++){
    cin>>tm[i]>>a>>b>>c;
    scr[i]=make_pair((-1)*(a*3+c),i);
  }
  sort(scr.begin(),scr.end());
  for(int i=0;i<n;i++)
    cout<<tm[scr[i].second]<<","<<(-1)*scr[i].first<<endl;
}

int main (){

  int n;

  while(cin>>n && n){
    solve(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,setcnt,ff;
	int win,lose,drow,mx=-1;
	char kuni[11][21];
	int tokuten[11];
	char team[21];
	setcnt=0;
	while(cin>>n) {
		if(setcnt!=0)cout<<endl;
		for(i=0;i<n;i++) {
			cin>>kuni[i]>>win>>lose>>drow;
			tokuten[i]=win*3+drow;
		}
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(mx<tokuten[j] && tokuten[j]!=-1) {
					mx=tokuten[j];
					ff=j;
					strcpy(team,kuni[j]);
				}
			}
			cout<<team<<","<<mx<<endl;
			tokuten[ff]=-1;mx=-1;
		}
		
		setcnt++;
	}
	return 0;
}