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>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int outcount=3,runner=0,point=0;
        while(outcount){
            string kind;
            cin>>kind;
            if(kind=="HIT")runner++;
            else if(kind=="HOMERUN"){
                point+=runner+1;
                runner=0;
            }
            else outcount--;

            if(runner>3){
                point++;
                runner--;
            }
        }
        cout<<point<<endl;

    }
    return 0;
}

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

using namespace std;

int main()
{
  int count;
  int out_count = 0;
  int first = 0;
  int second = 0;
  int third = 0;
  int point = 0;

  string h = "HIT";
  string o = "OUT";
  string home = "HOMERUN";

  cin>>count;

  while(1){
    string v;
    cin>>v;

    if(v == o){
      ++out_count;
      if(out_count%3 == 0){
        cout<<point<<endl;
        point = 0;
        first = 0;
        second = 0;
        third = 0;
      }
      if(out_count == count*3){
        break;
      }
    }
    else if(v == h){
      if(third == 1){
        point += 1;
        third = 0;
      }
      if(second == 1){
        third = 1;
        second = 0;
      }
      if(first == 1){
        second = 1;
      }
      first = 1;
    }
    else if(v == home){
      if(third == 1){
        point += 1;
        third = 0;
      }
      if(second == 1){
        point += 1;
        second = 0;
      }
      if(first == 1){
        point += 1;
        first = 0;
      }
      ++point;
    }
  }
  return 0;
}

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

using namespace std;

int main(){
	int n=0,ct=0, score=0, out=0,run=0;
	string x;
	cin >> n;
	while (1){
		int  score = 0, out = 0, run = 0;
		while (1){
			cin >> x;
			if (x == "OUT"){
				out++;
			}
			if (x == "HOMERUN"){
				score+=(run+1);
				run = 0;
			}
			if (x == "HIT"){
				run++;
			}
			if (run > 4){
				run--;
				score++;
			}
			if (out == 3){
				cout << score << endl;
				ct++;
				break;
			}
		}
		if (ct == n)break;
	}
	return 0;

}

C++: #include<stdio.h>
#include<string.h>
main(){
  int n;
  int out=0,hit=0,total_out=0;
  int point=0;
  char ibe[10];
  scanf("%d",&n);
  while(total_out!=3*n){
    scanf("%s",ibe);
    if(strcmp(ibe,"HIT")==0){
      hit++;
    }
    if(hit==4){
      point++;
      hit=3;
    }
    if(strcmp(ibe,"OUT")==0){
      out++;
      total_out++;
    }
    if(strcmp(ibe,"HOMERUN")==0){
      point+=hit+1;
      hit=0;
    }
    if(out==3){
      out=0;
      hit=0;
      printf("%d\n",point);
      point=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;
        }
        runner.push(1);
    }
    
    //ホームラン
    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 <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int main() {
    int n;
    cin >> n;
    int a = 0, b = 0, out = 0, ini = 0;
    int base[4] = {0};
    string s;
    while (cin >> s) {
        if (out == 3) {
            out = 0;
            ini++;
            REP(i,4) base[i] = 0;
        }
        if (s == "HIT") {
            for (int i = 2; i >= 0; i--) {
                if (base[i]) base[i+1] = 1, base[i] = 0;
            }
            base[0] = 1;
            if (base[3]) {
                if (ini % 2 + 1) a++;
                else b++;
                base[3] = 0;
            }
        }else if (s == "HOMERUN") {
            if (ini % 2 + 1) {
                REP(i,3) a += base[i];
                a++;
            }else {
                REP(i,3) b += base[i];
                b++;
            }
            REP(i,3) base[i] = 0;
        }else {
            out++;
        }
    }
    cout << a << endl << b << endl;
}

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

using namespace std;

int main(){
	int n , i = 1;
	int base = 0 , sum[3] = {} , out_count = 0;
	string str;

	cin >> n;
		
	while(1){
	    
		if(i > n) break;
		cin >> str;
		
		if(out_count >= 3){
			base = 0;
			i++;
		}
		if(base >= 4){
		    sum[i]++;
		    base = base - 1;
		}
		if(str == "HIT"){base++;}
		else if(str == "OUT"){out_count++;}
		else if(str == "HOMERUN"){
		    sum[i] += base + 1;
		    base = 0;
		}
		
	}
	cout << sum[1] << " " << sum[2] << endl;

	return 0;
}