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 <stdio.h>
#include <string.h>

int main() {
	int ining;
	int ten[50];
	int base[3];
	char act[8];
	int outCnt = 0;
	
	for(int i=0;i<50;i++){
		ten[i] = 0;
	}
	
	for(int i=0;i<3;i++){
		base[i] = 0;
	}
	
	scanf("%d",&ining);
	
	for(int i=0;i<ining;i++){
		while(outCnt < 3){
			scanf("%s",act);
			if(strcmp(act,"HIT") == 0) {
				ten[i] = ten[i] + base[2];
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			} else if(strcmp(act,"HOMERUN") == 0) {
				for(int l=0;l<3;l++){
					ten[i] = ten[i] + base[l];
					base[l] = 0;
				}
				ten[i] = ten[i] + 1;
			} else if(strcmp(act,"OUT") == 0) {
				outCnt++;
			}
		}
		outCnt = 0;
		for(int i=0;i<3;i++){
			base[i] = 0;
		}
	}
	
	for(int i=0;i<ining;i++)
		printf("%d\n",ten[i]);
	
	return 0;
}

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

int main(){
  int n,cou=0;
  string str;
  cin >> n;
  while(n>cou){
    int cou_out=0,ans=0,ining=0;
    while(cou_out < 3){
      cin >> str;
      if(str == "HIT"){
	ining++;
	if(ining == 4){
	  ans++;
	  ining--;
	}
      }
      else if(str == "OUT"){
	cou_out++;
      }
      else if(str == "HOMERUN"){
	ans += ining+1;
	ining = 0;
      }
    }
    cou++;
    cout << ans << endl;
  }
}#include<iostream>
#include<string>
using namespace std;

int main(){
  int n,cou=0;
  string str;
  cin >> n;
  while(n>cou){
    int cou_out=0,ans=0,ining=0;
    while(cou_out < 3){
      cin >> str;
      if(str == "HIT"){
	ining++;
	if(ining == 4){
	  ans++;
	  ining--;
	}
      }
      else if(str == "OUT"){
	cou_out++;
      }
      else if(str == "HOMERUN"){
	ans += ining+1;
	ining = 0;
      }
    }
    cou++;
    cout << ans << endl;
  }
}

C++: #include <cstdio>
#include <cctype>
#include <utility>
#include <string>
#include <vector>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
inline bool scan(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
void scan(string &s) {for (char c; !isspace(c = gcu()); s += c);}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int n = in();
	while (n--) {
		int OUT = 0, score = 0, runner = 0;
		while (OUT < 3) {
			string s;
			scan(s);
			switch (s[1]) {
			case 'I' :
				runner++;
				if (runner == 4) {
					score++;
					runner = 3;
				}
				break;
			case 'O' :
				score += runner + 1;
				runner = 0;
				break;
			default :
				OUT++;
			}
		}
		out(score, '\n');
	}
}

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

int main()
{
	string str;
	int n;
	int point=0,outcount=0,run=0;
	cin >> n;
	while(n != 0){
		cin >> str;
		if(str == "OUT"){
			outcount++;
			if(outcount == 3){
				cout << point << endl;
				point = 0;outcount=0;run=0;
				n--;
			}
		}
		else if(str == "HOMERUN"){
			point+=run+1;
			run = 0;
		}
		else if(str == "HIT"){
			run++;
			point += run/4;
			run -= run/4;
		}
	}
	return 0;
}

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


using namespace std;

class Player{
private:
  int  base;

public:
  Player(int i){
    base=1;
  }


  void SetBase(int a){
    this->base =a;
  }

  int GetBase(){
    return this->base;
  }
};

class Baseball{
private:
  int score;
  int out;
  queue<Player> que;

public:
  Baseball(){
      score = out=0;
  }

  void add_hit(int num){
    Player one(1);
    this->que.push(one);
    int length=this->que.size();

    for(int i= 0;i<length;i++){
      Player tmp = this->que.front();
      this->que.pop();
      int tmp_base=tmp.GetBase();
      if((tmp_base+num)>4){
        score++;
      }else{
        tmp.SetBase(tmp_base+num);
        this->que.push(tmp);
      }
    }
  }

  void add_out(){
    this->out++;
  }

  void add_score(){
    this->score++;
  }

  int GetOut(){
    return this->out;
  }

  int GetScore(){
    return this->score;
  }

  void show_score(){
    cout<<this->score<<endl;
  }

};

int main(void){
  int time;
  cin >> time;

  for(int i=0;i<time;i++){
    Baseball baseball;
    while(baseball.GetOut()!=3){
      string judge;
      cin>>judge;
      if(judge == "HIT"){
        baseball.add_hit(1);
      }else if(judge=="OUT"){
        baseball.add_out();
      }else if(judge=="HOMERUN"){
        baseball.add_hit(4);
      }

    }

    cout<<baseball.GetScore()<<endl;
  }

  return 0;
}

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

int main()
{
    int n;
    cin>>n;
    string s;
    int cnt=0,score=0,base=0;
    
    for(int i=0; i<n;){
        cin>>s;
        if(s=="HIT"){
            base++;
            if(base==4){
                base--;
                score++;
            }
        }
        else if(s=="HOMERUN"){
            score += base + 1;
            base = 0;
        }
        else if(s=="OUT"){
            cnt++;
        
            if(cnt==3){
                cout<<score<<endl;
                i++;
                cnt=0;
                score=0;
                base=0;
            }
        }
        
    }
    
    return 0;
}

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

class Baseball{
private:
  int point;
  int runner;
  int out_count;
  void hit();
  void homerun();
  void out();
public:
  Baseball(){
    point = 0;
    runner = 0;
    out_count = 0;
  }
  ~Baseball(){}
  
  void show_point(){ std::cout << point << std::endl;}
  void start();
};

void Baseball::hit(){
  ++runner;
  if(runner == 4){
    ++point;
    --runner;
  }
}

void Baseball::homerun(){
  point += runner + 1;
  runner = 0;
}

void Baseball::out(){
  ++out_count;
}

void Baseball::start(){
  while(out_count < 3){
    std::string event;
    std::cin >> event;
    if(event == "HIT"){ hit(); }
    else if(event == "HOMERUN"){ homerun(); }
    else if(event == "OUT"){ out(); }
  }
}
 
int main(){
  int data_num;
  std::cin >> data_num;

  for(int i = 0; i < data_num; ++i){
    Baseball baseball;
    baseball.start();
    baseball.show_point();
  }
  return 0;
}

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

using namespace std;

int main() {
	int n;
	string b;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int out = 0;
		int sco = 0;
		int rui[3] = {0};
		while (out != 3) {
			cin >> b;
			if (b == "OUT") {
				out++;
			} else if (b == "HIT") {
				for (int j = 2; j >= 0; j--) {
					if (rui[j] == 1) {
						if (j == 2) {
							sco++;
							rui[j] = 0;
						} else {
							rui[j+1] = 1;
							rui[j] = 0;
						}
					}
				}
				rui[0] = 1;
			} else {
				sco++;
				for (int j = 0; j < 2; j++) {
					if (rui[j] == 1) {
						rui[j] = 0;
						sco++;
					}
				}
			}
		}
		cout << sco << endl;
	}
	return 0;
}