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 <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 = 101; 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;

	while(1){
		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;
				cining++;
				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 <string>
#include <iostream>
using namespace std;
int N, c1, c2, c3, out, ret; string S;
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		c1 = 0, c2 = 0, c3 = 0, out = 0, ret = 0;
		while (out != 3) {
			cin >> S;
			if (S == "HIT") {
				ret += c3, c3 = c2, c2 = c1, c1 = 1;
			}
			else if (S == "HOMERUN") {
				ret += c1 + c2 + c3 + 1, c1 = 0, c2 = 0, c3 = 0;
			}
			else {
				out++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: int main(){
  int n;
  string input;
  int out;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    first = second = third = out = point = 0;
    out = 0;
    while(out < 3)
    {
      cin >> input;
      if(input == "OUT")
      {
        out++;
        continue;
      }
      else if(input == "HIT")
      {
        point += third;
        third = second;
        second = first;
        first = 1;
        continue;
      }
      else if(input == "HOMERUN")
      {
        point += first + second + third + 1;
        first = second = third = 0;
        continue;
      }
    }
    cout << point << endl;
  }
  return 0;
}

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

int main(){
	
	string sim ;
	int n;
	int base=0 , point=0 , count=0 ;
	
	cin >> n ;
	
	for( int i=0 ; i<n ;){
		cin >> sim ;
		
		if( sim == "HIT" ){
			base++;
			if( base == 4 ){
				base=3;
				point++;
			}
		}
		else if( sim == "HOMERUN" ){
			point += base+1 ;
			base=0;
		}
		else if( sim == "OUT" ){
			count++;
			if( count%3 == 0 ){
				cout << point << endl ;
				i++;
				base=0;
				point=0;
			}
		}
	}
	
return 0;
}

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

int main(){
	int n , score , runner , outcount;
	cin >> n;
	for(int i=0 ; i<n ; i++){
		score=runner=outcount=0;
		string event;
		while(outcount<3){
			cin >> event;
			if (event=="HIT"){
				if(runner==3){
					score++;
				} else {
					runner++;
				}
			} else if (event=="HOMERUN"){
				score+=runner+1;
				runner=0;
			} else {
				outcount++;
			}
		}
		cout << score << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>

int singlehit(char *base, int score);
int homerun(char *base, int score);

int main(void)
{
    int number;
    scanf("%d", &number);
    
    char event[10];
    int out_num;
    char base[4];
    while (number != -1){
        int score = 0;
        for (int i = 0; i < 4; i++){
            base[i] = '0';
        }
        for (out_num = 0; out_num != 3;){
            scanf("%s", event);
            if (strcmp(event, "HIT") == 0){
                score = singlehit(base, score);
            }
            else if (strcmp(event, "HOMERUN") == 0){
                score = homerun(base, score);
            }
            else {
                out_num++;
            }
        }
        printf("%d\n", score);
        number--;
    }
    
    return (0);
}

int singlehit(char *base, int score)
{
    base[1]++;
    if (base[1] == '2'){
        base[2]++;
        base[1]--;
    }
    if (base[2] == '2'){
        base[3]++;
        base[2]--;
    }
    if (base[3] == '2'){
        score++;
        base[3]--;
    }
    
    return (score);
}

int homerun(char base[], int score)
{
    for (int i = 0; i < 4; i++){
        if (base[i] == '1'){
            score++;
            base[i] = '0';
        }
    }
    score++;
    return (score);
}

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

using namespace std;

int main( void )
{
	long n;
	while(cin >> n) {
		string str;
		int outCount = 0, point = 0, base = 0;
		while(n) {
			cin >> str;
			switch(str[1]) {
				case 'I': // HIT
					++base;
					point += base/4;
					base = min(3, base);
					break;
				case 'U': // OUT
					if(++outCount == 3) {
						cout << point << endl;
						point = outCount = base = 0;
						--n;
					}
					break;
				case 'O': // HOMERUN
					point += base + 1;
					base = 0;
					break;
			}
		}
	}
	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 << judge << ' '<<baseball.GetOut()<<' '<<baseball.GetScore()<<endl;
    }

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

  return 0;
}

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

int main(){
	int n,ining=0;
	int hit=0,out=0,count=0;
	std::cin>>n;
	while(ining!=n){
		std::string str;
		std::cin>>str;
		if(str=="HIT"){
			hit++;
			if(hit==4)hit=3,count++;
		}else if(str=="HOMERUN"){
			count+=hit+1;
			hit=0;
		}else if(str=="OUT"){
			out++;
			if(out==3){
				hit=0;
				out=0;
				ining++;
				std::cout<<count<<std::endl;
				count=0;
			}
		}
	}
	return 0;
}