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>

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)
					break;
				
			}
		}
		std::cout >> "1" >> std::endl;
	}

	return 0;
}

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

int main(void)
{
	int base=0,out=0,score=0,e,i,j;
	char str[10];
	scanf("%d",&e);
	for(i=0;i<e;){
		scanf("%s",&str);
		if(!strcmp(str,"HIT"))base++;
		
		else if(!strcmp(str,"OUT")){
			out++;
		}
		
		else if(!strcmp(str,"HOMERUN")){
			score=score+base+1;
			base=0;
		}
		if(base>3){
			base--;
			score++;
		}
		if(out==3){
			out=0;
			printf("%d\n",score);
			i++;
			base=0;
			score=0;
		}
	}
	return 0;
}

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

int base[3], out = 0, score = 0, n, eventnum = 0, a = 0;
string event[106];

void Hit()
{
	base[2] = 0;
	if (base[1] == 1) base[2] = 1;
	if (base[0] == 1) 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 >> event[a];
			a++;
			eventnum++;
			if (event[a - 1] == "OUT") break;
		}
	}

	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++;
			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{
    private:
        std::queue<int> runner;
        int out_count = 0;
        int score = 0;
        
    public:
        void initRunner(){
            while(runner.empty() != true){
                runner.pop();
            }
            for(int i = 0; i < 3; ++i){
                runner.push(0);
            }
        }
        
        Baseball(){
            out_count = 0;
            score = 0;
            initRunner();
        }
        
        ~Baseball(){}
        
        void hit(){
            if(runner.back() == 1) ++score;
            runner.pop();
            runner.push(1);
        }
        
        void homerun(){
            do{
                if(runner.back() == 1) ++score;
                runner.pop();
            } while(runner.empty() != true);
            ++score;
            initRunner();
        }
        
        int getScore(){
            initRunner();
            std::string str;
            while(out_count != 3){
                std::cin >> str;
                if(str == "HIT") hit();
                if(str == "HOMERUN") homerun();
                if(str == "OUT") ++out_count;
            }
            return score;
        }
};

int main(void){
    int N;
    std::cin >> N;
    for(int i = 0; i < N; ++i){
        Baseball baseball;
        std::cout << baseball.getScore() << std::endl;
    }
}

C++: #include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		string dat;
		int ou=0,hi=0,ans=0;
		for(;;){
			cin>>dat;
			if(dat[0]=='O' && dat[1]=='U'){
			ou++;
			}
			else if(dat[0]=='H' && dat[1]=='I'){
			hi++;}
			else if(dat[0]=='H' && dat[1]=='O'){
			ans=ans+hi+1;
			hi=0;
			}
			if(ou==3){
				cout<<ans<<endl;
				break;
			}
			if(hi==4){
				ans++;
				hi--;
			}
		}
	}
	return 0;
}

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

void hit();
void homerun();
void out();
void is_end_of_game();

int inning = 0;										// イニング数
int first = 0, second = 0, third = 0;				// 0...走者無し　1...走者有り
int runs = 0, outs = 0;								// 1イニング毎のアウト数と得点
bool end_of_game = false;							// trueで試合終了
vector<int> score_board;							// スコアボード

int main()
{
	string event;
	cin >> inning;
	while(true) {
		cin >> event;
		if (event=="HIT")
			hit();
		else if (event=="HOMERUN")
			homerun();
		else if (event=="OUT")
			out();
		else {
			cout << "error; wrong order\n";
			return -1;
		}
		if(end_of_game)
			break;
	}
	for(int i=0;i<score_board.size();i++)
		cout << score_board[i] << '\n';

	return 0;
}

void hit()
{
	if(third==1) {
		third = 0;
		runs++;
	}
	if(second==1) {
		second = 0;
		third =1;
	}
	if(first==1) 
		second = 1;
	first = 1;
}

void homerun()
{
	runs += (first + second + third + 1);
	first = second = third = 0;
}

void out()
{
	outs++;
	if(outs==3) {
		score_board.push_back(runs);
		first = second = third = 0;
		outs = 0;
		runs = 0;
	}
	is_end_of_game();
}

void is_end_of_game()
{
	if(score_board.size()==inning)
		end_of_game = true;
}

C++: #include<stdio.h>

int main(void){

	int i,j,k,q,p,inning,point,kazu[20];
	char eve[10];
	
		point=0;
		j=0;
		k=0;
		q=0;
		p=0;	
	
		scanf("%d",&inning);
		
		for(k=0;k<inning;k++){
		
			point=0;
			j=0;
			q=0;
			p=0;
			
		while(q<3){
		
			for(j=0;j<10;j++){
				eve[j]=0;
			}
			
			scanf("%s",eve);
			
			if(eve[0]=='O'){
				if(eve[1]=='U'){
					if(eve[2]=='T'){
						q++;
					}
				}		
			}
			if(eve[0]=='H'){
				if(eve[1]=='I'){
					if(eve[2]=='T'){
						p++;
						if(p>=4){
							point++;
						}
					}
				}
			}		
			
			if(eve[0]=='H'){
				if(eve[1]=='O'){
					if(eve[2]=='M'){
						if(eve[3]=='E'){
							if(eve[4]=='R'){
								if(eve[5]=='U'){
									if(eve[6]=='N'){
										point=point+p+1;
										p=0;
									}
								}
							}
						}		
					}
				}
			}
		}		
		kazu[k]=point;
	}
	for(k=0;k<inning;k++){
		printf("%d\n",kazu[k]);
	}
	return 0;
}