Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

C++: //0103
#include<string.h>
#include<stdio.h>
int main()
{
	int n,op,f,se,t,r=0;
	char in[16];
	scanf("%d",&n);
	while(n--){
		r=0;
		op=0;
		f=0;
		se=0;
		t=0;
		while(op<3){
			scanf("%s",in);
			if(in[1] == 'I'){
				r+=t;
				t=se;
				se=f;
				f=1;
			}else if(in[1] == 'U'){
				op++;
			}else{
				r+=f+se+t+1;
				f=0;
				se=0;
				t=0;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n;
string str;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int out=0,ans=0;
		vector<bool> base(3);
		while(out<3){
			cin>>str;
			if(str=="OUT") out++;
			else if(str=="HIT"){
				for(int j=2;j>=0;j--){
					if(base[j]){
						if(j+1>2) ans++;
						else base[j+1]=1;
						base[j]=0;
					}
				}
				base[0]=1;
			}
			else{
				for(int j=0;j<3;j++){
					if(base[j]) ans++;
					base[j]=0;
				}
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

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

int main(){
	int inning,score;
	int out,runner;
	string str;
	cin>>inning;
	for(int i=0;i<inning;i++){
		score=runner=out=0;
		while(out<3){
			cin>>str;
			if(str=="OUT")out++;
			if(str=="HIT")runner++;
			if(runner==4){
				score++;
				runner--;
			}
			if(str=="HOMERUN"){
				score=score+runner+1;
				runner=0;
			}
		}
		cout<<score<<endl;
	}
}

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

int Baseball()
{
    const u_int num_of_event = 100;
    int num_of_runner = 0, num_of_out = 0, point = 0;
    std::string event;
    
    for(u_int i = 0; i < num_of_event; ++i){
        std::cin >> event;
        if(event == "HIT"){
            if(num_of_runner == 3)
                ++point;
            else
                ++num_of_runner;
        }
        else if(event == "HOMERUN"){
            point += 1 + num_of_runner;
            num_of_runner = 0;
        }
        else{
            ++num_of_out;
            if(num_of_out == 3)
                break;
    }
    
    return point;
}

int main()
{
    u_int num_of_inning;
    std::cin >> num_of_inning;
    
    for(u_int i = 0; i < num_of_inning; ++i){
        std::cout << Baseball() << std::endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    for(int z=0;z<n;z++){
        int out=0;
        int points=0;
        int run=0;
        while(out<3){
            string s; cin >> s;
            if(s=="OUT")out++;
            else if(s=="HIT"){
                run++;
                if(run==4){
                    points++;
                    run--;
                }
            }
            else{
                points+=(run+1);
                run=0;
            }
        }
        cout << points << endl;
    }
}

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

int main(void)
{
	int N,i,r,R,o;
	string ivent;
	cin >> N;
	i=0;
	r=0;
	R=0;
	o=0;
	
	while(1) {
		cin >> ivent;
		if(ivent=="HIT"){
			r++;
			if(r==4) {
				r--;
				R++;
			}
		}
	
		else if(ivent=="HOMERUN"){
			R+=r+1;
			r=0;
		}
	
		else if(ivent=="OUT"){
			o++;
			if(o==3){
				r=0;
				o=0;
				i++;
				cout << R << endl;
				R=0;
				if(i==N) return 0;
			}
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <stdlib.h>
 
using namespace std;
 
int main(void){
	
	int n;
	cin >> n;

	for( int i = 0; i < n; i++ ) {
		int outs = 0, runner = 0, pts = 0;
		while( outs < 3 ) {
			string evt;
			cin >> evt;
			if( evt == "HIT" ) {
				if( runner < 3 ) {
					runner ++;
				} else {
					pts ++;
				}
			} else if( evt == "OUT" ) {
				outs ++;
			} else {
				pts += runner + 1;
				runner = 0;
			}
		}
		cout << pts << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string.h>

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

using namespace std;

int main() {
	int n;
	int base = 0, out = 0, score = 0;
	cin >> n;  
    while(1) {
        char str[10];
        if(EOF == scanf("%s", str)) break;
        if(!strcmp(str, "OUT")) {
            out++;
            if(out >= 3) {
                cout << score <<endl;
                score = out = base = 0;
                n--;
            }
        } else if(!strcmp(str, "HOMERUN")) {
            score += base + 1;
            base = 0;
        } else {
            base++;
            if(base >= 4) {
                score++;
                base--;
            }
        }
    }
    if(n) {
        cout << score << endl;
    }
	return 0;
}

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

class Baseball{
	
private:
	//アウトカウント
	int out_count;
	//ランナー
	std::array<bool, 3> runner;
	//点数
	int point;
	
public:
	//コンストラクタ
	Baseball(){
		out_count = 0;
		for(int i = 0; i < 3; ++i) runner[i] = false;
		point = 0;
	}
	
	//デストラクタ
	~Baseball(){}
	
	//点数出力
	int get_point(){ return point; }
	
	//ゲーム開始
	void playball();
	
	//アウト判定
	void process_out();
	
	//ヒット判定
	void process_hit();
	
	//ホームラン判定
	void process_homerun();
};

//ゲーム開始
void Baseball::playball(){
	while(out_count < 3){
		std::string str;
		std::cin >> str;
		if(str == "OUT") process_out();
		else if(str == "HIT") process_hit();
		else if(str == "HOMERUN") process_homerun();
	}
}

//アウト判定
void Baseball::process_out(){
	++out_count;
}

//ヒット判定
void Baseball::process_hit(){
	if(runner[2]){
		++point;
		runner[2] = false;
	}
	if(runner[1]){
		runner[1] = false;
		runner[2] = true;
	}
	if(runner[0]){
		runner[0] = false;
		runner[1] = true;
	}
	runner[0] = true;
}

//ホームラン判定
void Baseball::process_homerun(){
	++point;
	for(int i = 0; i < 3; ++i){
		if(runner[i]){
			++point;
			runner[i] = false;
		}
	}
}


int main(){
	int count;
	std::cin >> count;
	
	for(int i = 0; i < count; ++i){
		Baseball baseball;
		
		baseball.playball();
		std::cout << baseball.get_point() << std::endl;
	}
	
	return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;

int n;
int count_HIT=0, count_OUT=0;
int Point[2] = {0,0};
int i=0;
string S;

void solve()
{
	while (count_OUT <3)
	{
		cin >> S;
		if (S == "HIT")
		{
			count_HIT++;
			if (count_HIT == 4)
			{
				Point[i]++;
				
				count_HIT -- ;
			}
		}
		else if (S == "HOMERUN")
		{
			Point[i] += count_HIT + 1;
			
			count_HIT = 0;
		}
		else count_OUT++;
	}
	count_OUT = 0; count_HIT = 0;
	i ^= 1;
	return;
}

int main()
{
	cin >> n;
	REP(j, n)
	{
		solve();
	}

	cout << Point[0] << endl
		<< Point[1] << endl;

	return 0;
}