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

int main(){
	const std::string single_hit("HIT");
	const std::string homerun("HOMERUN");
	const std::string out("OUT");
	
	
	std::queue<int> base;
	int out_count = 0;
	int score = 0;
	int game = 1;
	int num;
	std::string str;
	
	std::cin >> num;
	while(num){
		out_count = 0;
		score = 0;
		game = 1;
		while(game){
			std::cin >> str;
			if(str == single_hit){
					base.push(1);
					if(base.size() == 4){
						++score;
						base.pop();
					}
			}
			else if(str == homerun){
					score += base.size() + 1;
					while(base.size() !=0)	base.pop();
			}
			else if(str == out){
					++out_count;
					if(out_count == 3) game = 0;
			}
		}
		std::cout << score << std::endl;
		--num;
	}
	
	


}

C++: main(){
	int c,y,t,o,p;
	char a[9];
	scanf("%d",&c);
	for(y=0;y<c;y++){
		for(t=o=p=0;;){
			scanf("%s",a);
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}c=1;
}

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

using namespace std;

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];

	cin >> ining;

	for (int i = 0; i < 100; i++){
		cin >> 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 <iostream>
#include <array>

class Baseball{
private:
    int m_first = 0;
    int m_second = 0;
    int m_third = 0;
    int m_out = 0;
    int m_point = 0;

public:
    void isHit(){
        if(m_third == 1){
            m_third = 0;
            ++m_point;
        }
        if(m_second == 1){
            m_second = 0;
            m_third = 1;
        }
        if(m_first == 1){
            m_second = 1;
        }
        else {
            m_first = 1;
        }
    }
    void isHomerun(){
        m_point += m_first + m_second + m_third + 1;
        m_first = 0;
        m_second = 0;
        m_third = 0;
    }
    void setOut(){
        ++m_out;
    }
    int getOut(){
        return m_out;
    }
    int getPoint(){
        return m_point;
    }
};

int main(){
    int n;
    std::string event;

    std::cin >> n;
    Baseball baseball[n];
    //std::array<Baseball, n> baseball;
    for(int i = 0; i < n; ++i){
        while(baseball[i].getOut() < 3) {
            std::cin >> event;
            if (event == "HIT") {
                baseball[i].isHit();
            } else if (event == "OUT") {
                baseball[i].setOut();
            } else if (event == "HOMERUN"){
                baseball[i].isHomerun();
            }
        }
        std::cout << baseball[i].getPoint() << std::endl;
    }
}

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

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	int out = 0, runner = 0, point = 0;
	for(int i = 0; i < num; ++i){
		while(out < 3){
			std:: cin >> event;

			if(event == "OUT"){
				++out;		
			}else if(event == "HIT"){
				if(runner == 3){
					++point;
				}else{
					++runner;
				}
			}else if(event == "HOMERUN"){
				point += runner + 1;
				runner = 0;
			}
		}
		std::cout << point << std::endl;
		out = 0, runner = 0, point = 0;
	}
	return 0;
}

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

int base[6], out = 0, score = 0, n, eventnum = 0, a = 0;
vector<string> event;
string s;

void Hit()
{
	base[2] = 0;
	if (base[1]) base[2] = 1;
	if (base[0]) base[1] = 1;
	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 >> s;
			event.push_back(s);
			a++;
			eventnum++;
			if (event.at(a - 1) == "OUT") break;
		}
	}
	for (int i = 0; i < eventnum; i++) {
		if (event.at(i) == "HIT") {
			if (base[2] == 1) score += 1;
			Hit();
		}
		else if (event.at(i) == "HOMERUN")	{
			score += (base[0] + base[1] + base[2] + 1);
			Homerun();
		}
		else {
			out++;
			if (out == 3) {
				cout << score << endl;
				for (int j = 0; j < 3; j++) base[j] = 0;
				score = out = 0;
			}
		}
	}
	return 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(){
        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<cstdio>
#include<iostream>
#include<string>
using namespace std;
main(){
  int n,o=0,b1=0,b2=0,b3=0,p[40],i,l=0;
  string str;
  cin >> n;
  p[0]=0;
  while(n>l){
    cin >> str;
    if(str=="HIT"){
      b1++;
      if(b1>1){
	b2++;
	b1=1;
	if(b2>1){
	  b3++;
	  b2=1;
	  if(b3>1){
	    p[l]++;
	    b3=1;
	  }
	}
      }
    }
    if(str=="HOMERUN"){
      p[l]++;
      if(b1==1){
	p[l]++;
	b1=0;
      }
      if(b2==1){
	p[l]++;
	b2=0;
      }
      if(b3==1){
	p[l]++;
	b3=0;
      }
    }
    if(str=="OUT"){
      o++;
      if(o%3==0){
	l++;
	b1=0;
	b2=0;
	b3=0;
	p[l]=0;
      }
    }
  }
  for(i=0;i<l;i++){
    cout << p[i] << endl;
  }
}