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 <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<string> a(101);
    bool run[3]={false, false, false};
    int out=0, e=0;
    int point[50];
    int i=0;
    int k=0;
    while(cin >> a[i]) {
        if(a[i]=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a[i]=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        i++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }
    
}

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

class Baseball{
	int score;
	int out_count;
	std::array<bool, 3> runner;
	
public:
	Baseball(){
		score = 0;
		out_count = 0;
		for(int i = 0 ; i < 3 ; ++i){
			runner[i] = false;
		}
	}
	int get_score(){ return score; } //getter
	void start_inning();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::start_inning(){
	std::string event;
	
	while(out_count < 3){
		std::cin >> event;
		if(event == "HIT"){
			event_hit();
		}else if(event == "HOMERUN"){
			event_homerun();
		}else if(event == "OUT"){
			event_out();
		}
	}
}

void Baseball::event_hit(){
	if(runner[2]){
		++score;
		runner[2] = false;
	}
	if(runner[1]){
		runner[2] = true;
		runner[1] = false;
	}
	if(runner[0]){
		runner[1] = true;
		runner[0] = false;
	}
	runner[0] = true;
}

void Baseball::event_homerun(){
	for(int i = 0 ; i < 3 ; ++i){
		if(runner[i]){
			runner[i] = false;
			++score;
		}
	}
	++score;
}

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

int main(){
	int n; //number of inning
	std::cin >> n;
	
	while(n--){
		Baseball baseball;
		
		baseball.start_inning();
		std::cout << baseball.get_score() << std::endl;
	}
	
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
int GCD(int a, int b){
    if(b==0) return a;
    return GCD(b, a%b);
}

int main() {
    int n; cin >> n;
    int ans=0, cnt=0, out_cnt=0; 
    while(n){
        string s; cin >> s;
        if(s=="HIT"){
            cnt++;
            if(cnt==4){
                ans++;
                cnt--;
            }
        }else if(s=="HOMERUN"){
            ans += cnt+1;
            cnt=0;
        }else{
            out_cnt++;
            if(out_cnt==3){
                cnt=0;
                n--;
                out_cnt=0;
                cout << ans << endl;
                ans=0;
            }
        }
    }
	return 0;
}

C++: #include <iostream>
#include <string>
int main(void){
int datasets,i,hit=0,out,remain=0;
std::string input;
std::cin >> datasets;
for(i=0;i<datasets;++i){
	out=0;
	while(out<3){
		std::cin >> input;
		if(input=="HIT"){
			++hit;
			++remain;
		}
		if(input=="HOMERUN"){
			++hit;
			remain=0;
		}
		if(input=="OUT") ++out;
	}
	if(remain>3) remain=3;
	std::cout << hit-remain << std::endl;
	hit=0;
	remain=0;
}
return 0;
}

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

using namespace std;

int n, p, c, o;
string curr;

int main(void) {
    cin >> n;

    while(n > 0) {
        p = o = c = 0;
        while(1) {
            cin >> curr;
            if(curr == "HOMERUN") {
                p += c + 1;
                c = 0;
            } else if(curr == "OUT") {
                o += 1;
            } else {
                c += 1;
                if(c == 4) {
                    p += 1;
                    c -= 1;
                }
            }
            if(o == 3) break;
        }
        cout << p << endl;
        n--;
    }
    return 0;
}

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

int base[3] = { 0, 0, 0 };
int out = 0;
int score = 0;
int n;
string event[100];
int eventnum = 0;
int a = 0;

/*void Hit()
{
	if (base[2] == 1)
	{
		base[2] = 0;
	}
	if (base[1] == 1)
	{
		base[2] = 1;
	}
	if (base[0] == 1)
	{
		base[1] = 1;
	}
	else if (base[0] == 0)
	{
		base[0] = 1;
	}
}

void Homerun()
{
	for (int j = 0; j < 3; j++)
	{
		base[j] = 0;
	}
}*/

int main()
{
	cin >> n;
	for (int i = 0; i < 3 * n; i++)
	{
		while (true)
		{
			cin >> event[a];
			if (event[a] == "OUT")
			{
				a += 1;
				eventnum += 1;
				break;
			}
			else
			{
				a += 1;
				eventnum += 1;
			}

		}
	}

	/*for (int i = 0; i < eventnum; i++)
	{
		if (event[i] == "HIT")
		{
			if (base[2] == 1)
			{
				score += 1;
			}
			Hit();
		}
		else if (event[i] == "HOMERUN")
		{
			score += base[0] + base[1] + base[2] + 1;
			Homerun();
		}
		else
		{
			out += 1;
			if (out == 3)
			{
				cout << score << endl;
				for (int j = 0; j < 3; j++)
				{
					base[j] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}*/
}

C++: #include<stdio.h>
#include<string.h>
#include<memory.h>

int main(){
	int n,i=0,score=0,out=0,ining=0,base[10]={0};
	int j;
	char s[8];
	scanf("%d",&n);
	while(ining!=n){
		scanf("%s",s);
		if(strcmp(s,"HIT")==0){	
			base[i]=1;
			i++;
		}
		else if(strcmp(s,"HOMERUN")==0){
			if(i==0)score++;
			else score+=i+1;
			memset(base,0,sizeof(base));
		}
		else if(strcmp(s,"OUT")==0){
			out++;
		}
		if(base[3]==1){
			score++;
			base[3]=0;
		}
		if(out==3){
			ining++;
			printf("%d\n",score);
			score=0;
			out=0;
			i=0;
			memset(base,0,sizeof(base));
		}
	}
	return 0;
}