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>
#include<vector>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
int n,cnt=0;
	int out=0,ans=0,now=0;
cin>>n;
	for(;;){
	if(cnt==n)break;
	string tmp;
	cin>>tmp;
	if(tmp=="OUT")out++;
	else if(tmp=="HIT")now++;
	if(tmp=="HOMERUN")ans+=now+1,now=0;
	if(now==4)now=3,ans++;
	if(out==3){cout<<ans<<endl;cnt++;out=0,ans=0,now=0;}
	}
		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 < 3; j++) {
					if (rui[j] == 1) {
						rui[j] = 0;
						sco++;
					}
				}
			}
		}
		cout << sco << endl;
	}
	return 0;
}

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

vector<int> ans;
int main(){
  int n;
  
  cin >> n;
  for(int i=0; i<n; ++i){
    bitset<3> base{0};
    int flag = 0;
    int score = 0;
    string nock;

    while(flag!=3){
    cin >> nock;

    if(nock == "HIT"){
      if(base == 000){
	base = 001;
      }else if(base[2]){
	base = base << 1;
	base |= 001;
	++score;
      }else{
	base = base << 1;
	base |= 001;
      }
    }
    
    if(nock == "OUT"){
      ++flag;
      if(flag == 3){
	ans.push_back(score);
	//cout << "end" << endl;
      }
    }
    if(nock == "HOMERUN"){
      int j;
      j = base.count();
      score += j + 1;
      base = 000;
    }
    }
  }
  for(auto i:ans){
    cout << i << endl;
  }
  return 0;
}

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

int main(void){
  int in;
  cin >> in;
  for(int i = 0; i < in; i++){
    string event;
    int outCnt = 0, fb = 0, sb = 0, tb = 0, score = 0;
    while(outCnt != 3 && cin >> event){
      if(event == "HIT") { score += tb; tb = sb; sb = fb; fb = 1; }
      if(event == "HOMERUN") { score += fb + sb + tb + 1; fb = 0; sb = 0; tb = 0;};
      if(event == "OUT") outCnt++;
    }
    cout << score << endl;
  }
  return 0;
}

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

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

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

	//getter
	int getOut() { return out; }
	int getRunner() { return runner; }
	int getScore() { return score; }
	//input OUT
	void execOut() { ++out; }
	//input HIT
	void execHit() {
		if(runner == 3)++score;
		else ++runner;
	}
	//input HOMERUN
	void execHomerun() {
		score += runner + 1;
		runner = 0;
	}

};

int main(){
	int dataSetNum;
	std::cin >> dataSetNum;

	std::vector< Baseball > baseball;
	baseball.resize(dataSetNum);

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

		while(baseball[i].getOut() != 3){
			//input
			std::string tmp;
			std::cin >> tmp;

			if(tmp == "OUT")baseball[i].execOut();
			else if(tmp == "HIT")baseball[i].execHit();
			else if(tmp == "HOMERUN")baseball[i].execHomerun();
		}

	}
	//output
	std::for_each(baseball.begin(), baseball.end(),
    [](Baseball x) { std::cout << x.getScore() << std::endl; } );

	return 0;
}

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

int main(){
	int n;
	cin>>n;

	for(int i=0; i<n; i++)
	{
		int out=0,bass=0,point=0;
		string s;

		while(cin>>s)
		{
			if( s=="HIT") bass++;
			else if( s=="OUT" ) out++;
			else {
				point += bass+1;
				bass=0;
			}

			if( bass == 4 ) {
				point++;
				bass=bass-1;
			}
			if( out == 3 ) break; 
		}
		cout<<point<<endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() 
{
    int n;
    scanf("%d",&n);
    for (int ix=0; ix<n; ix++) {
        int out=0,score=0;
        int hit[] = {0,0,0};
        string event;
        while (out<3) {
            cin>>event;
            if (event=="HIT") {
                if (hit[2]==1) score++;
                if (hit[1]==1) hit[2]=1;
                if (hit[0]==1) hit[1]=1;
                hit[0]=1;
            }
            else if (event=="HOMERUN") {
                for (int i=0; i<3; i++) {
                    score+=hit[i];
                    hit[i]=0;
                }
                score++;
            }
            else if (event=="OUT") {
                out++;
            }
        }
        printf("%d\n",score);
    }
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;

int main() {
	int n;
	cin >> n;

	REP(hoge, n) {
		int hit = 0, score = 0, out = 0;
		string command;
		
		while(out < 3) {
			cin >> command;

			if(command == "OUT") {
				out++;
			} else if(command == "HIT") {
				if(hit == 3) {
					score++;
				} else {
					hit++;
				}
			} else if(command == "HOMERUN") {
				score += (hit+1);
				hit = 0;
			}
		}

		cout << score << endl;
	}

	return 0;
}