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 <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    cin>>n;
    rep(afewjo,n){
        int outc=0;
        int p=0;
        int fie[10]={};

        while(outc<3){
            string eve;
            cin>>eve;
            
            if(eve=="HIT"){
                if(fie[3]==1)p++;
                fie[3]=fie[2];
                fie[2]=fie[1];
                fie[1]=1;
            }else if(eve=="OUT"){
                outc++;
            }else if(eve=="HOMERUN"){
                p+=1+fie[1]+fie[2]+fie[3];
                fie[1]=fie[2]=fie[3]=0;
            }
        }
        cout<<p<<endl;
    }
    
    return 0;
}

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

class Baseball{
    u_int runner, out, point;
    
public:
    Baseball();
    ~Baseball(){}
        
    u_int get_runner() const {return runner;}
    u_int get_out() const {return out;}
    u_int get_point() const {return point;}
    void set_runner(const u_int r) {runner = r;}
    void set_out(const u_int o) {out = o;}
    void set_point(const u_int p) {point = p;}
    
    void event_hit();
    void event_homerun();
    void event_out();
    
private:
    void inc_runner() {++runner;}
    void inc_out() {++out;}
    void add_point(const u_int p) {point += p;}
};

Baseball::Baseball()
{
    runner = 0;
    out = 0;
    point = 0;
}

void Baseball::event_hit()
{
    if(get_runner() == 3){
        add_point(1);
    }
    else{
        inc_runner();
    }   
}

void Baseball::event_homerun()
{
    add_point(1 + get_runner());
    set_runner(0);
}

void Baseball::event_out()
{
    inc_out();
}

int main()
{
    u_int inning;
    std::cin >> inning;
    
    std::string event;
    for(u_int i = 0; i < inning; ++i){
        Baseball b_ball;
        while(b_ball.get_out() != 3){
            std::cin >> event;
            if(event == "HIT"){
                b_ball.event_hit();
            }
            else if(event == "HOMERUN"){
                b_ball.event_homerun();
            }
            else{
                b_ball.event_out();
            }
        }
        std::cout << b_ball.get_point() << std::endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void)
{
	int score = 0;
	int runner = 0;
	int out = 0;
	int inning = 1;
	int inning_limit;
	cin>>inning_limit;
	int inning_score[50] = {};
	bool rui_1 = false;
	bool rui_2 = false;
	bool rui_3 = false;
	string hit[100];
	int i = 0;
	
	while(cin>>hit[i]){
		if(hit[i] == "HIT"){
			if(rui_3==true){
				inning_score[inning]++;
				
			}else{
				runner++;
			}
			rui_3 = rui_2;
			rui_2 = rui_1;
			rui_1 = true;
		}else if(hit[i] == "HOMERUN"){
			inning_score[inning] += runner + 1;
			runner = 0;
			rui_1=false;
			rui_2=false;
			rui_3=false;
		}else if(hit[i] == "OUT"){
			out++;
			if(out== 3){
				runner = 0;
				out = 0;
				inning_score[inning + 1] = 0; 
				rui_1=false;
				rui_2=false;
				rui_3=false;
				score += inning_score[inning];
				if(inning >= inning_limit){
					break;
				}
				inning++;
			}
		}
		i++;
	}

	for(int j = 1; j <= inning_limit;j++){
		cout<<inning_score[j]<<endl;
	}
	
	return 0;
}

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

int OutCount,PointCount,HitCount;

int Check(const char* str){
  if( strcmp(str,"HIT") == 0 )
		return 0;
	
	else if( strcmp(str,"HOMERUN") == 0 )
		return 1;
	
	else if( strcmp(str,"OUT") == 0 )
		return 2;
}
int main(){
  int n;
	char Input[10];
	scanf("%d",&n);
	while( n-- ){
		OutCount=PointCount=HitCount=0;
		
		while(OutCount < 3){
			scanf("%s",Input);
			switch(Check(Input)){
				case 0:
					HitCount++;
					if(HitCount==4)++PointCount, --HitCount;
					break;
				case 1:
					PointCount+=HitCount+1;
					HitCount=0;
					break;
				case 2:
					OutCount++;
					break;
			}
		}
		printf("%d\n",PointCount);
	}
	return 0;
}

C++: b,o,s;main(a){for(scanf("%d");~scanf("%s",&a);)b=a%3?a&1?++o%3?b:(s=!printf("%d\n",b>3?s+b-3:s)):b+1:(s+=b+1);}

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

class Baseball {
    // 各ビットがそれぞれの塁のランナーの有無を表現する
    std::bitset<4> runners;
    u_int _out, _score;
public:
    Baseball() :_out(0), _score(0) {};
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() { ++_out; }
    void change();
    bool is_change() { return _out == 3; }
    u_int score() { return _score; }
};

void Baseball::hit() {
    runners <<=1;   // ランナーを1つずつ進める
    runners.set(0); // 一塁にランナーを置く
    // ホームインしたかどうか
    if (runners.test(3)) {
        ++_score;
        runners.reset(3);
    }
}

void Baseball::homerun() {
    _score += runners.count() + 1;
    runners.reset(); // ランナーをリセット
}

void Baseball::change() {
    _out = _score = 0;
    runners.reset();
}

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

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        do {
            std::cin >> event;
            if ("HIT" == event) {
                game.hit();
            } else if ("HOMERUN" == event) {
                game.homerun();
            } else if ("OUT" == event) {
                game.out();
            }
        } while (!game.is_change());

        std::cout << game.score() << std::endl;
        game.change();
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <bitset>
     
class Baseball{
    u_int score, out_count;
    std::bitset<4> runners; 
public:
    Baseball() : score(), out_count(){} //initializer list
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() {++out_count;}
    u_int getScore() {return score;}
    u_int getOutcount() {return out_count;}
};
    
void Baseball::hit(){
    runners <<= 1; //shift
    runners.set(0); //set runner
    if(runners.test(3)){
        ++score;
        runners.reset(3);
    }
}
    
void Baseball::homerun(){
    score += runners.count() + 1;
    runners.reset();
}
    
int main(){
    u_int inning;
    std::cin >> inning;
    for(u_int i = 0; i < inning; ++i){
        Baseball game;
        while(game.getOutcount() != 3){
            std::string event;
            std::cin >> event;
            if(event == "HIT"){
                game.hit();
            }else if(event == "HOMERUN"){
                game.homerun();
            }else if(event == "OUT"){
                game.out();
            }
        }
        std::cout << game.getScore() << std::endl;
    }
    return 0;
}