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>

int base;

int hit(){
	if(base==3) return 1;
	else base++;
	return 0;
}

int homerun(){
	base++;
	return base;
}

int main(){
	int inning;
	std::cin >> inning;

	for(int i=0;i<inning;i++){
		int outCount=0;
		int point=0;
		std::string result;
		base=0;
		while(outCount<3){
			std::cin >> result;

			if(result == "HIT"){
				point += hit();
			} else if(result == "HOMERUN"){
				point += homerun();
				base=0;
			} else if(result == "OUT"){
				outCount++;
			}
		}
		std::cout << point << std::endl;
	}

    return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(){
	int run,out,n,score;
	run=out=score=0;
	char eve[10];
	scanf("%d",&n);
	while(n--){
		while(out<2){
			scanf("%s",eve);
			if(strcmp(eve,"HIT")==0){
				run++;
				if(run>3) score++;
			}
			else if(strcmp(eve,"OUT")==0) out++;
			else if(strcmp(eve,"HOMERUN")==0){
				run=0;
				score++;
			}
		}
		printf("%d\n",score);
		run=out=score=0;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int base,i,j,n,o,point;
	char state[8];
	cin >> n;
	for(i=0;i<n;i++)
	{
		o=base=0;
		while(o<3)
		{
			cin >> state;
			if(state == "HIT")
			{
					if(base == 3)
						point++;
					else
						base++;
			}
			else if(state ==	"HOMERUN")
			{
					base++;
					point+= base;
					base =0;
					break;
			}
			else if(state == "OUT")
					o++;
		}
		cout << point << endl;
	}
	return 0;
}

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

class Baseball{
private:
    int m_runner = 0;
    int m_out = 0;
    int m_point = 0;

public:
    void isHit(){
        if(m_runner < 3){
            ++m_runner;
            //if fill all base    
        } else {
            ++m_point;
        }
    }
    void isHomerun(){
        //add point and reset runner
        m_point += m_runner + 1;
        m_runner = 0;
    }
    void setOut(){
        ++m_out;
    }
    int getOut(){
        return m_out;
    }
    int getPoint(){
        return m_point;
    }

    void resetInning(){
        m_runner = 0;
        m_out = 0;
        m_point = 0;
    }
};

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

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

C++: #include <stdio.h>
int main(){
    int h,o,p,t;
    char a[100];
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        h=o=p=0;
        while(o<3){
            scanf("%s",a);
            if(a[1]=='I'){
                if(h>2)p++;
                else h++;
            }
            if(a[1]=='O'){
                p=p+h+1;
                h=0;
            }
            if(a[1]=='U'){
                o++;
            }
        }
        printf("%d\n",p);
    }
}

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

using namespace std;

class Inning{
private:
  int out;
  int runnner;
  int point;
  int inningN;
public:
  Inning();//コンストラクタ
  void newInning();
  int getInningN(){return inningN;}
  int getPoint(){return point;}
  void doOut(){
    out ++;
    if(out == 3){
      newInning();
    }
  }
  void doHit();
  void doHomerun();
};

void Inning::doHit(){
  if(runnner < 3){
    runnner ++;
  }
  else{
    point ++;
  }
}
void Inning::newInning(){
  cout << point << endl;
  out = 0;
  runnner = 0;
  point = 0;
  inningN ++;
}

void Inning::doHomerun(){
  point += runnner + 1;
  runnner = 0;
}


//コンストラクタ
Inning::Inning(){
  out = 0;
  runnner = 0;
  point = 0;
  inningN = 0;
}

int main(){
  int N;
  char *str;
  cin >> N;
  Inning inning;

  while(1){
    if(inning.getInningN() == N){
      break;
    }
    cin >> str;
    if(!strcmp(str, "OUT")){
      inning.doOut();
    }
    if(!strcmp(str, "HIT")){
      inning.doHit();
    }
    if(!strcmp(str, "HOMERUN")){
      inning.doHomerun();
    }
  }

  return 0;
}

C++: #include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main()
{
    int point, runner[4], out, n;
    char event[16];
    scanf("%d", &n);
    point = out = 0;
    rep(i, 4) runner[i] = 0;
    while (true) {
        scanf("%s", event);
        runner[0] = 1;
        if (!strcmp(event, "HIT")) {
            if (runner[3]) point++;
            rep(i, 3) runner[3-i] = runner[2-i];
        }
        else if (!strcmp(event, "OUT")) {
            out++;
            if (out == 3) {
                printf("%d\n", point);
                n--;
                if (n == 0) break;
                point = out = 0;
                memset(runner, 0, sizeof(runner));
            }
        }
        else {
            rep(i, 4) if (runner[i]) point++;
            memset(runner, 0, sizeof(runner));
        }
    }
    return 0;
}

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

std::vector<unsigned int> res;

void solve() {
    int out=0, score=0;
    int base[4] = { 0 }; // base[0] : first
                         // base[1] : second
                         // base[2] : third
                         // base[3] : home
    std::string event;
    while (out < 3) {
        std::cin >> event;
        if (event == "OUT") {
            out++;
        } else if (event == "HOMERUN") {
            base[3] = 1;
            for (int i=0; i<4; i++) {
                score += base[i];
                base[i] = 0;
            }
        } else { // event == "HIT"
            int run=base[0];
            base[0] = 1;
            for (int i=1; i<4; i++) {
                std::swap(run, base[i]);
            }
            if (base[3] != 0) {
                score++;
                base[3] = 0;
            }
        }
    }
    std::cout << score << std::endl;
}

int main() {
    int n;
    std::cin >> n;
    for (int i=0; i<n; i++) {
        solve();
    }
}

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

int main() {
　　　int e;
　　　cin >> e;
　　　for(int i=0;i<e;i++){
　　　　　　int o=0,r=0,c=0;
　　　　　　while(1){
　　　　　　　　　string str;
　　　　　　　　　if(o==3) break;
　　　　　　　　　cin >> str;
　　　　　　　　　if(str=="HIT"){
　　　　　　　　　　　　if(r==3) c++,r--;
　　　　　　　　　　　　r++;
　　　　　　　　　}
　　　　　　　　　else if(str=="OUT") o++;
　　　　　　　　　else{
　　　　　　　　　　　　c+=r+1;
　　　　　　　　　　　　r=0;
　　　　　　　　　}
　　　}
　　　cout << c << endl;
　　　}
　　　return 0;
}

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

int main()
{
	int inning ;
	int point = 0 , out = 0 , runner = 0 ;
	char get[10] ;

	cin >> inning ;

	int i = 0 ;
	while( i < inning )
	{
		cin >> get ;
		if( strcmp(get,"HIT") == 0 )
		{
			runner ++ ;
			if( runner == 4 )
			{
				point ++ ;
				runner = 3 ;
			}
		}
		else if( strcmp(get,"HOMERUN") == 0 )
		{
			point += (runner+1) ;
			runner = 0 ;
		}
		else if( strcmp(get,"OUT") == 0 )
		{
			out ++ ;

			if( out == 3 )
			{
				cout << point << endl ;
				i ++ ;
				point = 0 ;
				out = 0 ;
				runner = 0 ;
			}
		}
	}
	return 0 ;
}