Go: // You Are the Judge(審判は君だ！)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2400&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Team struct {
	TID         int
	Accepted    int
	WrongAnswer map[int]int
	Penalty     int
}

type Teams []Team

func (t Teams) Len() int      { return len(t) }
func (t Teams) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t Teams) Less(i, j int) bool {
	// より多くの問題を解いたチームは順位が上になる
	if t[i].Accepted > t[j].Accepted {
		return true
	} else if t[i].Accepted == t[j].Accepted {
		// 解いた問題が同じ場合、ペナルティの少ないチームのほうが順位が上になる
		if t[i].Penalty < t[j].Penalty {
			return true
		} else if t[i].Penalty == t[j].Penalty {
			// 解いた問題もペナルティも同じ場合、チーム番号が小さいほうのチームが順位が上になる
			if t[i].TID < t[j].TID {
				return true
			}
		}
	}
	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		t, p, r := nextInt(sc), nextInt(sc), nextInt(sc)
		if t == 0 && p == 0 && r == 0 {
			break
		}

		teams := []Team{}
		for tID := 0; tID < t; tID++ {
			teams = append(teams, Team{tID + 1, 0, map[int]int{}, 0})
		}

		for i := 0; i < r; i++ {
			tID, pID, time, message := nextInt(sc), nextInt(sc), nextInt(sc), nextString(sc)
			tID--

			if message == "CORRECT" {
				teams[tID].Accepted++
				wa, _ := teams[tID].WrongAnswer[pID]
				teams[tID].Penalty += wa*1200 + time
			} else {
				teams[tID].WrongAnswer[pID]++
			}
		}

		sort.Sort(Teams(teams))

		for _, team := range teams {
			fmt.Println(team.TID, team.Accepted, team.Penalty)
		}
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <stdio.h>
#include <algorithm>

using namespace std;

int T, P, R;

int WAcnt[50][10];
int ACcnt[50];
int pena[50];
int gtID[50];

bool input() {
  int i;
  int tID, pID, time;
  char s[8];

  scanf("%d %d %d", &T, &P, &R);
  if (!T && !P && !R) return false;

  fill(WAcnt[0], WAcnt[0] + 50 * 10, 0);
  fill(ACcnt, ACcnt + 50, 0);
  fill(pena, pena + 50, 0);
  for (i = 0; i < R; i++) {
    scanf(" %d %d %d %s", &tID, &pID, &time, s);
    tID--;
    pID--;
    if (s[0] == 'C') {
      ACcnt[tID]++;
      pena[tID] += WAcnt[tID][pID] * 1200 + time;
    } else {
      WAcnt[tID][pID]++;
    }
  }

  return true;
}

int main() {
  int i, j, tmp;


  while (input()) {
    for (i = 0; i < T; i++) {
      gtID[i] = i;
    }

    for (i = 0; i < T - 1; i++) {
      for (j = T - 1; j > i; j--) {
        if (ACcnt[j - 1] < ACcnt[j]) {
          tmp = ACcnt[j];
          ACcnt[j] = ACcnt[j - 1];
          ACcnt[j - 1] = tmp;
          tmp = pena[j];
          pena[j] = pena[j - 1];
          pena[j - 1] = tmp;
          tmp = gtID[j];
          gtID[j] = gtID[j - 1];
          gtID[j - 1] = tmp;
        } else if (ACcnt[j - 1] == ACcnt[j] && pena[j - 1] > pena[j]) {
          tmp = ACcnt[j];
          ACcnt[j] = ACcnt[j - 1];
          ACcnt[j - 1] = tmp;
          tmp = pena[j];
          pena[j] = pena[j - 1];
          pena[j - 1] = tmp;
          tmp = gtID[j];
          gtID[j] = gtID[j - 1];
          gtID[j - 1] = tmp;

        } else if (pena[j - 1] == pena[j] && gtID[j - 1] > gtID[j]) {
          tmp = ACcnt[j];
          ACcnt[j] = ACcnt[j - 1];
          ACcnt[j - 1] = tmp;
          tmp = pena[j];
          pena[j] = pena[j - 1];
          pena[j - 1] = tmp;
          tmp = gtID[j];
          gtID[j] = gtID[j - 1];
          gtID[j - 1] = tmp;

        }
      }



    }

    for (i = 0; i < T; i++) {
      printf("%d %d %d\n", gtID[i] + 1, ACcnt[i], pena[i]);
    }


  }


  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;


struct NODE{
	int num;//team number
	vector<int> wrong;
	ll score;
	int solve;
	NODE(){}
	NODE(int num, int p):num(num), wrong(p, 0){score = 0; solve = 0;}
	
	bool operator<(const NODE r){
		if(solve != r.solve) return solve < r.solve;
		return score > r.score;
	}
};

int main() {
	
	int t, p, r;
	while(cin >> t >> p >> r, t){
		vector<NODE> v(t);
		rep(i, t){
			v[i] = NODE(i, p);
		}
		
		rep(i, r){
			int tid, pid, time;
			string mes;
			cin >> tid >> pid >> time >> mes;
			tid--;
			pid--;
			if(mes == "CORRECT"){
				v[tid].score += (v[tid].wrong[pid] * 1200 + time);
				v[tid].solve++;
			}
			else{
				v[tid].wrong[pid]++;
			}
		}
		
		SORT(v);
		
		for(int i = t-1; i >=0; i--){
			cout << v[i].num+1 << " " << v[i].solve << " " << v[i].score << endl;
		}
	}
	
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>

#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
using namespace std;

typedef struct{
	int wrong[11];
	int correct;
	int p_time;
	int num;
}Team;

int T, P, R;

void sswap(Team *a, Team *b){
	Team temp = *a;
	*a = *b;
	*b = temp;
}
void solve(Team team[]){
	rep(i, 0, T - 1)
	for (int j = T - 1; j > i; j--)
	{
		if (team[j].correct > team[j - 1].correct)
			sswap(team + j, team + j - 1);
		else if (team[j].correct == team[j - 1].correct){
			if (team[j].p_time < team[j - 1].p_time)
				sswap(team + j, team + j - 1);
			else if (team[j].p_time == team[j - 1].p_time&&team[j].num < team[j - 1].num)
				sswap(team + j, team + j - 1);
		}



	}
}

int main(){

	cin >> T >> P >> R;
	while (T != 0){
		Team team[51] = { { 0 }, 0, 0 };
		rep(i, 0, T)team[i].num = i + 1;
		rep(i, 0, R){
			int t, p, time;
			char str[20];
			cin >> t >> p >> time >> str;
			t--;
			if (strcmp(str, "WRONG")){
				team[t].correct++;
				team[t].p_time += time + team[t].wrong[p] * 1200;
			}
			else{
				team[t].wrong[p]++;
			}

		}
		solve(team);
		rep(i, 0, T){
			cout << team[i].num << " " << team[i].correct << " " << team[i].p_time << endl;
		}
		cin >> T >> P >> R;
	}
	return(0);
}

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

typedef struct TreamInfo
{
    int tID;
    int points;
    int pena;
    int ProbMiss[10];

    TreamInfo(int tid) : tID(tid) {}
} TeamInfo;

bool cmp(const TeamInfo &a, const TeamInfo &b)
{
    return (a.points == b.points)?(a.pena == b.pena? a.tID < b.tID:a.pena < b.pena):(a.points > b.points);
}

int main()
{


    while (true)
    {
        int t, p, r;
        cin >> t >> p >> r;
        if (t == 0 && p == 0 && r == 0)
            break;

        vector<TeamInfo> v;

        for (size_t i = 0; i < t; i++)
        {
            v.push_back(TeamInfo(i+1));
        }

        for (size_t i = 0; i < r; i++)
        {
            int tID, pID, tim;
            string mess;
            cin >> tID >> pID >> tim >> mess;

            if (mess == "CORRECT")
            {
                v[tID - 1].points += 1;
                v[tID - 1].pena += ((v[tID - 1].ProbMiss[pID - 1]) * 1200) + tim;
            }
            if (mess == "WRONG")
            {
                v[tID - 1].ProbMiss[pID - 1] += 1;
            }
        }
        // for (size_t i = 0; i < t; i++)
        // {
        //     cout << "team " << i <<" point is " <<v[i].points << endl;
        //     cout << "team " << i << " pena is " << v[i].pena << endl;
        // }

        sort(v.begin(), v.end(), cmp);
        for (size_t i = 0; i < t; i++)
        {
            cout << v[i].tID <<" "<< v[i].points <<" "<< v[i].pena << endl;
        }
    }
    return 0;
}