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++: #include <iostream>
using namespace std;

int main() {
    int N;
    cin >> N;

    for (int n = 0; n != N; ++n) {
        string event;
        int runners = 0, points = 0, out = 0;
        
        while (cin >> event && out < 3) {
            if (event == "HIT") {
                if (runners == 3) {
                    points++;
                }
                else {
                    runners++;
                }
            }
            else if (event == "HOMERUN") {
                points += runners + 1;
                runners = 0;
            }
            else {
                out++;
            }
        }
        cout << points << endl;
    }
}

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

int main(void) {
    u_int n;
    std::string event;

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        std::bitset<4> runner;
        u_int out = 0, score = 0;

        do {
            std::cin >> event;
            if ("HIT" == event) {
                runner <<= 1;   // 走者を1つずつ進める
                runner.set(0);  // 一塁に走者を置く
                if (runner.test(3)) { // ホームインしたかどうか
                    ++score;
                    runner.reset(3);
                }
            } else if ("HOMERUN" == event) {
                score += runner.count() + 1;
                runner.reset(); // 走者をリセット
            } else if ("OUT" == event) {
                ++out;
            }
        } while (out != 3);

        std::cout << score << std::endl;
    }

    return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n,i=0,out=0,g=0;
	int cange=0,score[2]={0,0};
	char evn[100][7];
	int base[4]={0,0,0,0};
	cin >> n;
	while(n!=g){
		cin >> evn[i];
		if(evn[i][1]=='I'){
			base[3]+=base[2];
			base[2]=base[1];
			base[1]=base[0];
			base[0]=1;
		}
		if(evn[i][1]=='O'){
			base[3]+=base[2]+base[1]+base[0]+1;
			base[2]=0;
			base[1]=0;
			base[0]=0;
		}
		if(evn[i][0]=='O'){
			out++;
		}
		if(out==3){
			out=0;
			base[0]=0;
			base[1]=0;
			base[2]=0;
			if(cange==0){
				score[0]+=base[3];
				base[3]=0;
				cange=1;
				g++;
			}
			else{
				score[1]+=base[3];
				base[3]=0;
				cange=0;
				g++;
			}
		}
	}
	cout << score[0] << endl <<score[1] << endl;
return 0;
}

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

using namespace std;

int n;
int o;
string s;

int rui[4]={0};

int main(){
    cin>>n;
    while(n!=0){
        cin>>s;
        if(s=="HIT"){
            for(int i=3; i>=1; i--){
                if(rui[i-1]!=0){
                    rui[i]+=rui[i-1];
                    rui[i-1]--;
                }
            }
            rui[0]++;
        }else if(s=="HOMERUN"){
            for(int i=2; i>=0; i--){
                rui[3]+=rui[i];
                rui[i]=0;
            }
            rui[3]++;
            
        }else if(s=="OUT"){
            o++;
            if(o==3){
                n--;
                cout<<rui[3]<<endl;
                for(int i=3; i>=0; i--){
                    rui[i]=0;
                    o=0;
                }
            }
        }
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
	int base,i,j,n,o,point;
	char state[8];
	cin >> n;
	for(i=0;i<n;i++)
	{
		o=base=0;
		while(o<3)
		{
			cin >> state;
			if(state == "HIT")
			{
				cout << "k" << endl;
					if(base == 3)
						point++;
					else
						base++;
			}
			else if(state ==	"HOMERUN")
			{
					cout << "k" << endl;
					base++;
					point+= base;
					base =0;
					break;
			}
			else if(state == "OUT")
					o++;
		}
		cout << point << endl;
	}
	return 0;
}

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

int main(void)
{
	string instr;
	int N;

	cin >> N;

	while(N--, N >= 0){
		int out = 0;
		int pos[4] = {};

		while(out < 3){
			cin >> instr;

			if(instr == "HIT"){
				if(pos[2]){
					pos[3] += pos[2];
					pos[2] = 0;
				}
				swap(pos[2],pos[1]);
				swap(pos[1],pos[0]);
				pos[0] = 1;
			}
			else if(instr == "HOMERUN"){
				pos[3] += pos[0] + pos[1] + pos[2];
				pos[0] = pos[1] = pos[2] = 0;
			}
			else if(instr == "OUT")
				out++;
	//		cout << pos[0] << ' ' << pos[1] << ' ' << pos[2] << ' ' << pos[3] << endl;
		}
		cout << pos[3] << endl;
	}
			

	return 0;
}

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

class Baseball{
	int point,out_count,runner;
public:
	Baseball(){
		point = 0;
		out_count = 0;
		runner = 0;
	}
	void game();
	void single_hit();
	void homerun();
	void out();
	int get_point(){ return point; }
	int get_out(){ return out_count; }
};

void Baseball::game(){
	std::string event;
	while(std::cin >> event){
		if(event == "HIT"){
			single_hit();
		}else if(event == "HOMERUN"){
			homerun();
		}else if(event == "OUT"){
			out();
		}
		if(get_out() == 3){
			break;
		}
	}
}

void Baseball::single_hit(){
	++runner;
	if(runner == 4){
		++point;
		--runner;
	}
}

void Baseball::homerun(){
	++runner;
	point += runner;
	runner = 0;
}

void Baseball::out(){
	++out_count;
}

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

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

int base[3];
int point = 0;
int out = 0;
int n;

//イニング終わり
void reset_base() {
	for (int i = 0; i < 3; ++i) {
		base[i] = 0;
	}
}

//シングルヒット
void Single_hit() {
	point += base[2];
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
}

//ホームラン
void HomeRun() {
	for (int i = 0; i < 2; ++i) {
		point += base[i];
		base[i] = 0;
	}
	++point;
}

void Out() {
	++out;
	if (out == 3) {
		reset_base();
		out = 0;
		cout << point << endl;
		point = 0;
		--n;
	}
}


int main() {
	cin >> n;
	string s;
	while (n) {
		cin >> s;
		if (s == "HIT") {
			Single_hit();
		}
		else if (s == "HOMERUN") {
			HomeRun();
		}
		else if (s == "OUT") {
			Out();
		}
	}
}

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 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<edge> edges;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n;
	cin >> n;
	REP(x, n)
	{
		string s;
		int cntout = 0;
		int run = 0;
		while (cin >> s)
		{
			if (s == "OUT") cntout++;
			if (cntout == 3)
			{
				int sum = 0;
				run >>= 3;
				while (run > 0)
				{
					if (run & 1) sum++;
					run >>= 1;
				}
				cout << sum << endl;
				break;
			}
			if (s == "HIT")
			{
				run <<= 1;
				run += 1;
			}
			if (s == "HOMERUN")
			{
				run <<= 1;
				run += 1;
				run <<= 3;
			}
		}
	}
	return 0;
}