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.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(){
  out = 0;
  runnner = 0;
  inningN ++;
  cout << point << endl;
}

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 <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;

string s[3]={"HIT","HOMERUN","OUT"};


int main(){
	int n;
	cin>>n;
	rep(i,n){
		string t;
		int score=0,out=0;
		bool first=false,second=false,third=false;
		while(1){
			cin>>t;
			if(t==s[0]){
				if(third){
					score++;
					third=false;
				}
				if(second){
					third=true;
					second=false;
				}
				if(first){
					second=true;
				}
				first=true;
			}
			if(t==s[1]){
				score++;
				if(first){
					first=false;
					score++;
				}
				if(second){
					second=false;
					score++;
				}
				if(third){
					third=false;
					score++;
				}
			}
			if(t==s[2]){
				out++;
				if(out==3){
					cout<<score<<endl;
					break;
				}
			}
		}
	}
}

C++: #include <iostream>
#include <string>
 
class Baseball
{
    u_int runner, out, point;
     
public:
    Baseball();
    ~Baseball(){}
         
    u_int get_out() const {return out;}
    u_int get_point() const {return point;}
    
    void game();
    void event_hit();
    void event_homerun();
    void event_out();
     
private:
    void set_runner(const u_int r) {runner = r;}
    void inc_runner() {++runner;}
    void inc_out() {++out;}
    void add_point(const u_int p) {point += p;}
};
 
Baseball::Baseball()
{
    runner = 0;
    out = 0;
    point = 0;
}

void Baseball::game()
{
    std::string event;
    while(get_out() != 3){
        std::cin >> event;
        if(event == "HIT"){
            event_hit();
        }
        else if(event == "HOMERUN"){
            event_homerun();
        }
        else{
            event_out();
        }
    }
} 

void Baseball::event_hit()
{
    if(get_runner() == 3){
        add_point(1);
    }
    else{
        inc_runner();
    }   
}
 
void Baseball::event_homerun()
{
    add_point(1 + get_runner());
    set_runner(0);
}
 
void Baseball::event_out()
{
    inc_out();
}
 
int main()
{
    u_int inning;
    std::cin >> inning;
     
    for(u_int i = 0; i < inning; ++i){
        Baseball b_ball;
        b_ball.game();
        std::cout << b_ball.get_point() << std::endl;
    }
 
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int solve(){
  int base=0,out=0,point=0;
  string key;
  while(out!=3){
    cin>>key;
    if(key=="HIT"){
      if(base&1<<2)point++;
      base<<=1;base++;
    }else if(key=="HOMERUN"){
      point++;
      for(int j=0;j<3;j++)if(base&1<<j)point++;
      base=0;
    }else if(key=="OUT")out++;
  }
  return point;
}
int main(){
  int a;
  cin>>a;
  for(int i=0;i<a;i++)cout<<solve()<<endl;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;



int main(){

	char buf[30];
	int n,sum,runner_num,out_count;

	scanf("%d",&n);

	for(int i=0; i < n; i++){

		sum = 0,runner_num = 0,out_count=0;

		while(out_count < 3){
			scanf("%s",buf);

			switch(buf[1]){
			case 'I':
				runner_num++;
				if(runner_num == 4){
					sum += 1;
					runner_num = 3;
				}
				break;
			case 'O':
				sum += runner_num + 1;
				runner_num = 0;
				break;
			case 'U':
				out_count++;
				break;
			}
		}
		printf("%d\n",sum);
	}
    return 0;
}

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

int main(void) {
  int n;
  string event;

  cin >> n;
  while(n--) {
    int out = 3;
    int ret = 0;
    int runner = 0;
    
    while(out) {
      cin >> event;
      if(event == "HIT") runner++;
      if(event == "OUT") out--;
      if(event == "HOMERUN") {
	ret+=(runner+1);
	runner=0;
      }
      if(runner==4) { runner--; ret++; }
    }
    cout << ret << endl;
  }

  return 0;
}

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

int type(string s){
	if(s == "HIT")return 0;
	if(s == "OUT")return 1;
	if(s == "HOMERUN")return 2;
}
int main(){
	int n;
	string s;
	cin >> n;
	
	while(n--){
		int outCount = 0;
		int base = 0;
		int result = 0;
		while(outCount < 3){
			cin >> s;
			switch(type(s)){
			case 0:
				base <<= 1;
				base++;
				break;
			case 1:
				outCount++;
				break;
			case 2:
				result += __builtin_popcount(base)+1;
				base = 0;
				break;
			}
			if(base & 8)result++;
			base &= 7; // 0b0111
			cout << s << base << endl;
		}
		cout << result << endl;
	}
}

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

class Baseball{
	private:
	int out;
	int runner;
	int point;

	public:
	void init();
	int get_out();
	int get_point();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::init(){
	out = 0;
	runner = 0;
	point = 0;
}

int Baseball::get_out(){
	return out;	
}

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

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

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

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

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	Baseball base;
	base.init();
	for(int i = 0; i < num; ++i){
		while(base.get_out() < 3){
			std:: cin >> event;

			if(event == "OUT"){
				base.event_out();		
			}else if(event == "HIT"){
				base.event_hit();
			}else if(event == "HOMERUN"){
				base.event_homerun();
			}
		}
		std::cout << base.get_point() << std::endl;
		base.init();
	}
	return 0;
}

C++: #include<stdio.h>

int main(){
	int c,y,t,o,p;
	char a[9];
	read(0,c,4);
	for(y=0;;y++){
		for(t=o=p=0;;){
			if(!~scanf("%s",a))return 0;
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}
}