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<stdio.h>
#include<string.h>
int main(void)
{
	int HIT=0,HOMERUN=0,OUT=0,POINT[2]={0},a,b,c=0;
	char EVENT[100][8];	
	for(;;)
	{
		scanf("%d",&a);
		for(b=0;;b++)
		{
			scanf("%s",EVENT[b]);
			if(strcmp(EVENT[b],"OUT")==0)
				OUT++;
			if(strcmp(EVENT[b],"HIT")==0)
			{
				HIT++;
				if(HIT==4)
				{
					POINT[c]++;
					HIT--;
				}
			}
			if(strcmp(EVENT[b],"HOMERUN")==0)
			{
				POINT[c]+=HIT+1;
				HIT=0;
			}
			if(OUT==3)
			{
				OUT=0;
				HIT=0;
				c++;
			}
			if(c==a)
			{
				printf("%d\n%d\n",POINT[0],POINT[1]);
				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;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int base[3] = { 0, 0, 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 i = 0; i < 3; i++)
	{
		base[i] = 0;
	}
}

int main()
{
	int out = 0;
	int score = 0;
	int n;
	string event[100];
	int eventnum = 0;

	cin >> n;
	int a = 0;
	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 i = 0; i < 3; i++)
				{
					base[i] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}
}

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


class Baseball {
public:
    int score;                //得点
    int count;                //アウトカウント
    std::queue<int> runner;   //ランナー

    //コンストラクタ
    Baseball(int sc,int co){
        score = sc;
        count = co;
        while(!runner.empty()){
            runner.pop();
        }
    }
    
    //ヒット
    void hit(){
        runner.push(1);
        if(runner.size() == 3)
            ++score;
    }
    
    //ホームラン
    void homerun(){
        while(!runner.empty()){
            ++score;
            runner.pop();
        }
        ++score;;
    }
    
    //アウト
    void out(){
        ++count;
    }
};


int main(){
    int n;
    std::string event;
    
    std::cin >> n;
    
    Baseball game(0,0);
    
    while(n > 0 && std::cin >> event){
        if(event =="HIT")
            game.hit();
        else if(event == "HOMERUN")
            game.homerun();
        else
            game.out();
        
        if(game.count == 3){
            --n;
            std::cout << game.score << std::endl;
            game = Baseball(0,0);
        }
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int out = 0;
	int r1 = 0;
	int r2 = 0;
	int r3 = 0;
	int t = 0;
	string k;
	int a = 0;
	cin >> a;
	for (int i = 1; i <= a; i++)
	{
		out = 0;
		t = 0;
		r1 = 0;
		r2 = 0;
		r3 = 0;
		while (out != 3)
		{
			cin >> k;
			if (k == "OUT")
			{
				out++;
			}
			if (k == "HIT")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					r3 = 1;
					r2 = 0;
				}
				if (r1 == 1)
				{
					r2 = 1;
					r1 = 0;
				}
			}
			if (k == "HOMERUN")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					t++;
					r2 = 0;
				}
				if (r1 == 1)
				{
					t++;
					r1 = 0;
				}
				t++;

			}
		}
		cout << t << endl;
	}
	
	return 0;
}

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 j=0;
    int k=0;
    while(cin >> a[j]) {
        if(a[j]=="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[j]=="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]++;
        }
        j++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }

}

C++: #include<iostream>
using namespace std;
int n,o,a,b,c,p;
string s;
main()
{
    cin>>n;
    while(cin>>s)
    {
        o=p=a=b=c=0;
        do{
            if(s=="OUT")o++;
            else if(s=="HIT")
            {
                if(c)p++,c=0;
                if(b)b=0,c=1;
                if(a)a=0,b=1;
                a=1;
            }
            else
            {
                p+=a+b+c+1;a=b=c=0;
            }
        }while(o<3&&cin>>s);
        cout<<p<<endl;
    }
}

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

using namespace std;

int main(){
	int N;
	int ening=0;

	cin>>N;
	vector <int> tokuten;
	while(ening<N){
		int out=0;
		int point=0;
		bool base[3]={false};
		while(out<3){
			string str;
			cin>>str;
			int runner=0;
			switch (str[1])
			{
			
			case 'I'://HIT
				if(base[2]){
					point++;
					base[2]=false;
				}
				for(int i=1;i>=0;i--){
					if(base[i]){
						base[i]=false;
						base[i+1]=true;
					}
				}
				base[0]=true;
				break;
			case 'O'://HOMERUN
				
				for(int i=0;i<3;i++){
					if(base[i]){
						runner++;
					}
					base[i]=false;
				}
				point+=++runner;
				break;
			case 'U'://OUT
				out++;
				break;
			}
		}
		cout<<point<<endl;
		ening++;
	}

	return 0;
}