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 <iostream>
#include <string>
#include <queue>

class Baseball{
	
	//field
	int score, out_count;
	std::queue<int> runners;
public:
	Baseball();
	~Baseball(){}
	
	//関数
	void hit();
	void homerun();
	void out();
	//setter,getter
	/*
	void set_score(int s) {score = s;}
	void set_out(int o) {out_count = o;}
	*/
	int get_score() {return score;}
	int get_out() {return out_count;}
};

//コンストラクタ
Baseball::Baseball()
{
	score = 0;
	out_count = 0;
}

void Baseball::hit(){
	runners.push(1);
	if(runners.size() == 4){
		++score;
		runners.pop();
	}
}

void Baseball::homerun(){
	score += runners.size() + 1;
	while(runners.size() != 0){
		runners.pop();
	}
}

void Baseball::out(){
	++out_count;
}
//クラスのフィールドアクセス？？
//キュー以外のいい感じのライブラリ探す？
int main(){
	int inning;
	std::string event;
	std::cin >> inning;
	//inningの回数だけループ
	for(int i = 0; i < inning; ++i){
		Baseball game;
		while(game.get_out() != 3){
			std::cin >> event;
			if(event == "HIT"){
				game.hit();
			}
			else if(event == "HOMERUN"){
				game.homerun();
			}
			else if(event == "OUT"){
				game.out();
			}
		}
	std::cout << game.get_score() << std::endl;
	}
}

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


class Baseball{
	int out;
	std::string runner;
	int score;
public:
	Baseball(){
		out = 0;
		runner.clear();
		score = 0;
	}
	
	int get_score(){ return score;}
	void event_out(){ ++out;}
	void event_hit();
	void event_homerun();
	void play_game();
};


void Baseball::event_hit(){
	int place;
	if((place = runner.find("3", 0)) != -1){
		runner.erase(place);
		++score;
	}
	
	if((place = runner.find("2", 0)) != -1){
		runner.replace(place, 1, "3");
	}
	
	if((place = runner.find("1", 0)) != -1){
		runner.replace(place, 1, "2");
	}
	
	runner.insert(0, "1");
}

void Baseball::event_homerun(){
	score += runner.size() + 1;
}

void Baseball::play_game(){
	std::string event;
	while(std::cin >> event){
		if(event == "HIT"){
			event_hit();
		}
		if(event == "HOMERUN"){
			event_homerun();
		}
		if(event == "OUT"){
			event_out();
			if(out == 3){
				break;
			}
		}
	}
}

int main(){
	int game_num;
	std::cin >> game_num;
	for(int i = 0; i < game_num; ++i){
		Baseball baseball;
		baseball.play_game();
		std::cout << baseball.get_score() << std::endl;
	}
	
	return 0;
}

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

	for(int i = 0; i < N; ++i){

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT")
				baseball.add_out();
			
			if(baseball.get_out() == 3){
				int P = 1;
				std::cout >> P >> std::endl;
				break;
			}
		}

	}

	return 0;
}

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

int base=0;
int score = 0;
int out=0;

void addRunner(){
	switch (base){
	case 0:base = 1; break;
	case 1:base = 11; break;
	case 10:base = 11; break;
	case 11:base = 111; break;
	case 100:base = 1; score++; break;
	case 101:base = 11; score++; break;
	case 111:base = 111; score++; break;
	default:printf("any error"); break;
	}
}

int main(){
	int cining=0,ining;
	char eventName[9];

	scanf("%d",&ining);
	for (int i = 0; i < 100; i++){
		scanf("%s",eventName);
		if (strcmp("HIT", eventName) == 0){
			addRunner();
		}
		else if (strcmp("OUT",eventName) == 0){
			out++;
			if (out == 3){
				printf("%d\n", score);
				score = out = base = 0;
				if (cining == ining)break;
			}
		}
		else if (strcmp("HOMERUN", eventName) == 0){
			switch (base){
			case 0:score++; break;
			case 1:score += 2; break;
			case 10:score += 2; break;
			case 11:score += 3; break;
			case 100:score += 2; break;
			case 101:score += 3; break;
			case 110:score += 3; break;
			case 111:score += 4; break;
			default:printf("any error"); break;
			}
			base = 0;
		}
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[4],k=0,l=0;
  string s;
  cin>>n;
  while(k!=n){
    cin>>s;
    if(s=='H'){
      if(!a[0])a[0]++;
      else {
        if(!a[1])a[1]++;
        else{
          if(!a[2])a[2]++;
          else a[3]++;
        }
      }
    }
    else if(s=='O'){
      l++;
      if(l==3){
        a[1]=a[2]=a[0]=l=0;
        k++;
      }
    }
    else{
    a[3]+=1+a[1]+a[2]+a[0];
    a[1]=a[2]=a[0]=0;
    }
  }
  cout<<a[3]<<endl;
}

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(){
		point = 0;
		out = 0;
		base = 0;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

	for(int i = 0; i < N; ++i){

		Baseball baseball;

		while(baseball.get_out() != 3){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT")
				baseball.add_out();

		}

		std::cout >> baseball.get_point() >> std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int n,score, nout,ining;
int base[4];
string s;
int main(){
	cin >> n;
	while(1){
		cin >> s;
		if(s=="HIT"){
			score+=base[3];
			base[3]=base[2];
			base[2]=base[1];
			base[1]=1;
		}else if(s=="HOMERUN"){
			score+=1+base[1]+base[2]+base[3];
			base[1]=base[2]=base[3]=0;
		}else if(s=="OUT"){
			nout++;
			if(nout==3){
				if(ining==n)break;
				ining++;
				cout << score<< endl;
				nout=0;
				score=0;
				base[1]=base[2]=base[3]=0;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

class Base {
private:
  int runner;

public:
  Base() : runner(0) {}
  int hit() {
    int point = (runner & 4) >> 2;
    runner <<= 1;
    runner |= 1;
    return point;
  }
  int homerun() {
    int point = 1;
    for (int i = 0; i <3; ++i) {
      point += (runner >> i) & 1;
    }
    runner <<= 3;
    return point;
  }
};

void solve(int n) {
  for (int i = 0; i < n; ++i) {
    int point = 0;
    int out = 0;
    Base base = Base();

    while(out < 3) {
      string s;
      cin >> s;
      if (s == "HIT")          point += base.hit();
      else if (s == "HOMERUN") point += base.homerun();
      else                     out++;
    }
    cout << point << endl;
  }

}

int main() {
  int n;
  cin >> n;
  solve(n);
}