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 <cstdio>
#include <cstring>

using namespace std;

class Inning {
 public:
  enum class Event { Hit, Homerun, Out };
  Inning() : bases_({ false, false, false }), out_count_(0), score_(0) {}
  int GetScore() { return score_; }
  bool IsFinished() { return out_count_ >= 3; }
  void Update(Event event) {
    switch (event) {
      case Event::Hit:
        if (bases_[2]) { ++score_; }
        bases_[2] = bases_[1];
        bases_[1] = bases_[0];
        bases_[0] = true;
        break;
      case Event::Homerun:
        score_ += CountRunners() + 1;
        bases_[2] = false;
        bases_[1] = false;
        bases_[0] = false;
        break;
      case Event::Out:
        ++out_count_;
        break;
    }
  }
 private:
  int CountRunners() {
    int count = 0;
    for (int i = 0; i < 3; ++i) { if (bases_[i]) { ++count; } }
    return count;
  }
  bool bases_[3];
  int out_count_;
  int score_;
};

Inning::Event ToEvent(const char *event_name) {
  if (strcmp(event_name, "HIT") == 0) { return Inning::Event::Hit; }
  if (strcmp(event_name, "HOMERUN") == 0) { return Inning::Event::Homerun; }
  return Inning::Event::Out;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    Inning inning;
    while (!inning.IsFinished()) {
      char event[40];
      scanf("%s", event);
      inning.Update(ToEvent(event));
    }
    printf("%d\n", inning.GetScore());
  }
  return 0;
}

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

int main(void){
	int n;
	cin>>n;
	while(n--){
		string s;
		valarray<int> h(3);
		int o=0;
		int sc=0;
		h=0;
		while(o!=3){
			cin>>s;
			if(s[0]=='O')o++;
			else if(s[1]=='I'){
				sc+=h[2];
				h=h.shift(-1);
				h[0]=1;
			}else{
				sc+=1+h.sum();
				h=0;
			}
		}
		cout<<sc<<endl;
	}
	return 0;
}

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

int main(){
  int n;
  int base[3];
  int out, score;
  
  std::string event;
  std::cin >> n;
  for(int i=0; i<n; i++){
    base[0] = 0;
    base[1] = 0;
    base[2] = 0;
    out = 0;
    score = 0;
    while(out!=3){
      std::cin >> event;
      if(event=="HIT"){
        if(base[2]>=1){
          base[2]--;
          score++;
        }
        if(base[1]>=1){
          base[1]--;
          base[2]++;
        }
        if(base[0]>=1){
          base[0]--;
          base[1]++;
        }
        base[0]++;
      }else if(event=="HOMERUN"){
        score++;
        score += base[2];
        base[2] = 0;
        score += base[1];
        base[1] = 0;
        score += base[0];
        base[0] = 0;
      }else{
        out++; 
      }
    }
    std::cout << score << std::endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
 
int main() {
    int n,i,p,ten,out;
    char d[3]={'I','U','O'},ch[8];
    cin >> n;
    for (n;n>0;n--) {
        p=0; out=0; ten=0;
        while(out<3) {
            cin >> ch;
            for (i=0;i<3;i++) if (ch[1]==d[i]) break;
            if (i==0) { ten+=p & 1; p=(p/2) | 4;}
            if (i==1) out++;
            if (i==2) { ten+=(p & 4)/4+(p & 2)/2+(p & 1)+1; p=0;}
            }
        cout << ten << endl;
    }
    return 0;
    }

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

int main() {
  int n;
  cin >> n;
  while(n--) {
    int runner = 0;
    int score = 0;
    int mask = (1<<3)-1;
    int n_out = 0;
    while(1) {
      string s;
      cin >> s;
      if(s == "HIT") {
        runner = ( (runner<<1) | 1 ) ;
        score += __builtin_popcount(runner & ~mask);
        runner &= mask;
      } else if(s == "HOMERUN") {
        score += __builtin_popcount(runner) + 1;
        runner = 0;
      } else if(s == "OUT") {
        if(++n_out == 3) {
          cout << score << endl;
          break;
        }
      }
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
void inning() {
  int out = 0, runner = 0, score = 0;
  string ev;
  while(out < 3) {
	cin >> ev;
	if(ev == "OUT") {
	  out++;
	  if(out == 3) break;
	}
	else if(ev == "HOMERUN") {
	  score += runner + 1;
	  runner = 0;
	}
	else if(ev == "HIT") {// hit
	  if(runner == 3) score++;
	  else runner++;
	}
  }
  cout << score << endl;
}
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
	inning();
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  while(n --> 0){
    int out = 0;
    int run = 0;
    int p = 0;
    while( out < 3 ){
      string str;
      cin >> str;
      if(str == "HIT"){
        run++;
        if(run == 4){
          p++;
          run = 3;
        }
      }else if(str == "OUT"){
        out++;
      }else{
        p += run + 1;
        run = 0;
      }
    }
    cout << p << endl;
  }
  return 0;
}

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

class Baseball{
private:
	int point;
	int out_count;
	int runner;
public:
	Baseball();
	void singleHit();
	void homerun();
	void out();
	void new_inning();
	int get_out_count();
	int get_point();
	~Baseball() = default;
};

Baseball::Baseball(){
	new_inning();
}

void Baseball::singleHit(){
	if(runner < 3){
		++runner;
	}
	else if(runner == 3){
		++point;
	}
}

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

}

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

void Baseball::new_inning(){
	point = 0;
	out_count = 0;
	runner = 0;
}

int Baseball::get_out_count(){
	return out_count;
}

int Baseball::get_point(){
	return point;
}

int main(){
	int num;
	std::cin >> num; //data set number
	Baseball baseball;
	std::string event;
	
	for(int i=0; i<num; ++i){
		baseball.new_inning();
		
		while(baseball.get_out_count() < 3){
			std::cin >> event;
			
			if(event == "HIT"){
				baseball.singleHit();
			}
			else if(event == "HOMERUN"){
				baseball.homerun();
			}
			else if(event == "OUT"){
				baseball.out();
			}
		}
		//output
		std::cout << baseball.get_point() << std::endl;
	}

}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  string ibe;
  int n;
  int score=0,out=0;
  int hit=0;
  cin >> n;
  for(int i=0;i<n;i++){
    while(1){
      if(out >= 3)break;
      cin >> ibe;
      if(ibe=="HIT"){
	hit++;
	if(hit==4){
	  score++;
	  hit--;
	}
      }
      else if(ibe=="HOMERUN"){
	score=hit+1+score;
	hit=0;
      }
      else if(ibe=="OUT"){
	out++;
      }
    }
    cout << score << endl;
    out=0;
    hit=0;
    score=0;
  }
}