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;

int main(){
	char input[10];
	int loc = 0, all = 0;
	int point = 0;
	int out;
	int gar;

	cin >> gar;
	out = 3;
	while(gar != 0){
		cin >> input;
		if( strcmp(input, "HIT") == 0 ){
			loc++;
			if(loc > 3){
				loc--;
				point++;
			}
				
		}else if( strcmp(input, "OUT") == 0){
			out--;
			if(out == 0){
				out = 3;
				gar--;
				loc = 0;
			}
		}else if( strcmp(input, "HOMERUN") == 0){
			point++;
			point += loc;
			loc = 0;
		}
	}
	cout << point << endl;

}

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;
        }
        else
            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<cstring>
using namespace std;
int main(){
  int n;
  cin>>n;
  int out=0;
  int score;
  string a;
  bool rui[3]={0};
  for(int i=0;i<n;i++){
    out=0; score=0;
    for(int j=0;j<3;j++){
      rui[j]=false;
    }
    while(out<3){
      cin>>a;
      if(a=="OUT")out++;
      if(a=="HIT"){
	if(rui[2]){rui[2]=false;score++;}
	if(rui[1]){rui[1]=false;rui[2]=true;}
	if(rui[0]){rui[0]=false;rui[1]=true;}
	rui[0]=true;
      }
      if(a=="HOMERUN"){
	score++;
	for(int j=0;j<3;j++){
	  if(rui[j]){rui[j]=false;score++;}
	}
      }
    }
    cout<<score<<endl;
  }
}

C++: #include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int base[3] = {0, 0, 0};

void Hit()
{
	if (base[2] == 1)
	{
		base[2] = 0;
	}
	if (base[1] == 1)
	{
		base[2] = 1;
	}
	if (base[0] == 1)
	{
		base[1] = 1;
	}
	else if (base[0] == 0)
	{
		base[0] = 1;
	}

}

void Homerun()
{
	for (int i = 0; i < 3; i++)
	{
		base[i] = 0;
	}
	
}

int main()
{
	int out = 0;
    int score = 0;
	int n;
	string s;
    vector <string> event;
	int eventnum = 0;

	cin >> n;
	int a = 0;
	for (int i = 0; i < 3 * n; i++)
	{
		while (true)
		{
			cin >> s;
			event.push_back(s);
			if (event.at(a) == "OUT")
			{
				a += 1;			
				eventnum += 1;
				break;
			}
			else
			{
				a += 1;
				eventnum += 1;
			}

		}
	}

	for (int i = 0; i < eventnum; i++)
	{
		if (event.at(i) == "HIT")
		{
			if (base[2] == 1)
			{
				score += 1;
			}
			Hit();
		}
		else if (event.at(i) == "HOMERUN")
		{
			score += base[0] + base[1] + base[2] + 1;
			Homerun();
		}
		else
		{
			out += 1;
			if (out == 3)
			{
				cout << score << endl;
				for (int i = 0; i < 3; i++)
				{
					base[i] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}

	return 0;
}

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

int main(){

  int n;
  cin >> n;
  while(n){
    int out = 0,hit = 0,point= 0;
    while(out != 3){
      string s;
      cin >> s;
      if(s == "OUT") out++;
      else if(s == "HIT"){
	hit++;
	if(hit == 4){
	  point++;
	  hit = 3;
	}
      }
      else if(s == "HOMERUN"){
	point += hit + 1;
	hit = 0;
      }
     
    }
    cout << point<<endl;
    n--;
  }
  return 0;
}

C++: #include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string a;
    int b,p,o;
    while(n--, n>=0){
        b = p = o = 0;
        while( cin >> a){
            if (a=="HIT"){
                b += 1;
                if (b >= 4){
                    b = 3;
                    p += 1;
                }
            } else if (a=="OUT"){
                o += 1;
                if (o >= 3) {
                    printf("%d\n",p);
                    break;
                }
            } else if (a=="HOMERUN"){
                p += b+1;
                b = 0;
            }
        }
    }
    return 0;
}

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

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

using namespace std;

int main() {
	int n;
	int base = 0, out = 0, count = 0;
	cin >> n;
	string str;
	while(1) {
		if(EOF == scanf("%s", str)) break;
		if(str == "OUT") {
			out++;
			cout << out << endl;
			if(out >= 3) {
				cout << count <<endl;
				count = out = base = 0;
				n--;
			}
		} else if(str == "HOMERUN") {
			count += base + 1;
			base = 0;
		} else {
			base++;
			if(base >= 4) {
				count++;
				base--;
			}
		}
	}
	cout << count << endl;
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		int count = 0,out = 0;
		int home[4];
		memset(home,0,sizeof(home));
		while(out != 3)
		{
			string s;
			cin >> s;

			if(s == "OUT")
			{
				out++;
			}
			else if(s == "HIT")
			{
				if(home[2] == 1)
				{
					home[2]--;
					home[3]++;
				}
				if(home[1] == 1)
				{
					home[1]--;
					home[2]++;
				}
				if(home[0] == 1)
				{
					home[0]--;
					home[1]++;
				}

				home[0]++;
			}
			else if(s == "HOMERUN")
			{
				if(home[2] == 1)
				{
					home[2]--;
					home[3]++;
				}
				if(home[1] == 1)
				{
					home[1]--;
					home[3]++;
				}
				if(home[0] == 1)
				{
					home[0]--;
					home[3]++;
				}
				home[3]++;
			}
		}
		count = home[3];
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
 
using namespace std;
 
int main(int argc, char **argv)
{
    int n, o, h, t;
    string s;
    cin >> n;
     
    while(n--){
        o = h = t = 0;
        while(o < 3){
            cin >> s;
            if(s == "HIT"){
                if(h == 3){
                    t++;
                } else {
                    h++;
                }
            } else if(s == "HOMERUN"){
                t = t + h + 1;
                h = 0;
            } else {
                o++;
            }
        }
        cout << t << endl;
    }
     
    return 0;
}