Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

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

int base[3] = {0, 0, 0};

int 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;
	}

	return 0;
}

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

	return 0;
}

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

int main()
{
   int n, outcnt = 0, point = 0;
   string str;

   queue<bool> que;

   cin >> n;

   for( int i = 0; i < n; ++i )
   {
      while(outcnt != 3)
      {
         cin >> str;

         if( str == "HIT" )
         {
            que.push(true);
            if( que.size() == 4 )
            {
               que.pop();
               ++point;
            }
         }
         else if( str == "HOMERUN" )
         {
            point += que.size() + 1;
            while( !que.empty() ) que.pop();
         }
         else if( str == "OUT" )
         {
            ++outcnt;
         }
      }
      cout << point << endl;
      outcnt = point = 0;
      while( !que.empty() ) que.pop();
   }
}

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

#define HIT 1
#define HR 2
#define OUT 3

int main(void){
    int outCnt, pt;
    int runner; // use bits
    char event[8];
    int eventID;
    int n;
    bool endInning;
    
    scanf("%d", &n);    
    for (int i=0; i<n; i++){
        endInning = false;
        outCnt = runner = pt = 0;
        while (!endInning){
            scanf("%s", event);
            if (event[0]=='O') eventID=OUT;
            else if (event[1]=='I') eventID=HIT;
            else eventID=HR;
            switch (eventID){
            case HIT:
                if (runner & 0x4) pt++;
                runner = (runner<<1) & 0x7;
                runner |= 0x1;
                break;
            case HR:
                pt++;
                if (runner & 0x4) pt++;
                if (runner & 0x2) pt++;
                if (runner & 0x1) pt++;
                runner = 0;
                break;
            case OUT:
                if (++outCnt == 3) endInning = true;
                break;
            }
        }
        printf("%d\n",pt);
    }
    
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n--) 
	{
		bool one=false,two=false,three=false;
		int out=0,ans=0;
		while(1) 
		{
			string in; cin>>in;
			if(in=="OUT")
			{
				out++;
				if(out==3) break;
			}
			else if(in=="HOMERUN")
			{
				int cnt=1;
				cnt+=one?1:0;
				cnt+=two?1:0;
				cnt+=three?1:0;
				one=two=three=false;
				ans+=cnt;
			}
			else
			{
				if(three) ans+=1;
				three=two; two=one; one=true;
			}
		}
		cout<<ans<<endl;
	}
  return 0;
}

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

int main(){
	int i, n, run, out, score;
	string str;
	cin>>n;
	for(i=0;i<n;i++){
		score=run=out=0;
		while(true){
			cin>>str;
			if(str == "HIT"){
				if(run<3) run++;
				else score++;
			}
			if(str == "OUT"){
				out++;
				if(out>=3){
					cout<<score<<endl;
					break;
				}
			}
			if(str == "HOMERUN"){
				score+=run+1;
				run=0;
			}
		}
	}
	return 0;
}

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

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner;
	
	public:
	
	Baseball(){
		out_count = 0;
		runner = {0,0,0,0};
	}
	
	void ining(){
		while(out_count != 3){
			std::string str;
			std::getline(std::cin, str);
		
			if(str == "HIT")
				hit();
			else if(str == "OUT")
				out();
			else homerun();
		}
		
		std::cout << runner[3] << std::endl;
		return;
	}
	
	void hit(){
		int i;
		for(i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
		}
		++runner[i];
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
	}
};

int main(){
	int n;
	std::cin >> n;
	
	for(int i=0; i<n; ++i){
		Baseball game;
		game.ining();
	}
	
	return 0;
}

C++: #include<cstdio>

int main() {
	bool a = false, b = false, c = false;
	int score = 0;
	char event[10];
	int d;
	scanf_s("%d", &d, 10);
	for (int i = 0; i<d; i++) {
		score = 0;
		a = b = c = false;
		int out = 0;
		while (1) {
			scanf_s("%s", &event, 10);
			if (event[1] == 'I') {
				if (c)score++;
				c = b;
				b = a;
				a = true;
			}
			else if (event[1] == 'O') {
				score++;
				if (a)score++;
				if (b)score++;
				if (c)score++;
				a = b = c = false;
			}
			else out++;
			if (out == 3) {
				printf("%d\n", score);
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main()
{
	int n; cin >> n ;
	while(n--)
	{
		int score=0; int out=0; int run=0;
		string str;
		while(cin>>str)
		{
			if(str=="HIT") {run++; if(run>=4) {run--; score++;} }
			else if(str=="HOMERUN") {score+=run+1; run=0;}
			else if(str=="OUT") out++;
			if(out>=3) break;
		}
		cout << score << endl;
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <time.h>
#include<string>
using namespace std;
int main(){
	int sumperson=0,n,out=0,score=0;
	string str;
	cin>>n;
	for(int i=0;i<n;i++){
		while(1){
			cin>>str;
			if(str=="OUT"){
				out++;
				if(out==3){
					break;
				}
			}
			else if(str=="HIT"){
				sumperson++;
				if(sumperson==4){
					sumperson=3;
					score++;
				}
			}
			else if(str=="HOMERUN"){
				score+=sumperson+1;
				sumperson=0;	
			}
		}
		cout<<score<<endl;
		sumperson=0;
		out=0;
		score=0;
	}
	return 0;
}