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++: //Name: Baseball Simulation
//Level: 1
//Category: やるだけ
//Note:

/**
 * 仕様のとおりに実装する。
 *
 * オーダーは O(E)。
 * ただし、Eはイベントの個数。
 */
#include <iostream>
#include <string>

using namespace std;

bool solve() {
    int out = 0;
    int b1 = 0, b2 = 0, b3 = 0;
    int score = 0;
    while(out < 3) {
        string event;
        cin >> event;
        if(event == "HIT") {
            if(b3) ++score;
            b3 = b2; b2 = b1; b1 = 1;
        } else if(event == "HOMERUN") {
            score += b1+b2+b3+1;
            b1 = b2 = b3 = 0;
        } else if(event == "OUT") {
            ++out;
        }
    }
    cout << score << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}

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

using namespace std;

int first, second, third, point;

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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	cin>>n;
	rep(i,n){
		string str;
		int out=0;
		int rui=0;
		int score=0;
		for(;out<3;){
			cin>>str;
			if(str=="HIT"){
				if(rui==3)score++;
				else rui++;
			}
			if(str=="HOMERUN"){
				score+=rui+1;
				rui=0;
			}
			if(str=="OUT"){
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll cmin = INF, cmax = -1, sum = 0;
	REP(i, n) {
		ll a;
		cin >> a;
		cmin = min(cmin, a);
		cmax = max(cmax, a);
		sum += a;
	}
	cout << cmin << " " << cmax << " " << sum << 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<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int N;
   cin>>N;
   while(N--)
   {
     string com;
     int arr[3]={0};
     int score=0;
     int out=0;
     while(cin>>com)
     {
       if(com=="OUT") out++;
       if(out==3) break;
       if(com=="HIT")
       {
         if(arr[0]==0) arr[0]++;
         else if(arr[1]==0) arr[1]++;
         else if(arr[2]==0) arr[2]++;
         else score++;              
       }
       if(com=="HOMERUN")
       {
         score+=(arr[0]+arr[1]+arr[2]+1);
         arr[0]=0;
         arr[1]=0;
         arr[2]=0;                  
       }
     }          
     cout<<score<<endl;
   }
   //while(1);
   return 0;
 }

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

using namespace std;

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

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int out = 0;
	int r1 = 0;
	int r2 = 0;
	int r3 = 0;
	int t = 0;
	string k;
	int a = 0;
	cin >> a;
	for (int i = 1; i <= a; i++)
	{
		out = 0;
		r1 = 0;
		r2 = 0;
		r3 = 0;
		while (out != 3)
		{
			cin >> k;
			if (k == "OUT")
			{
				out++;
			}
			if (k == "HIT")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					r3 = 1;
					r2 = 0;
				}
				if (r1 == 1)
				{
					r2 = 1;
					r1 = 0;
				}
			}
			if (k == "HOMERUN")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					t++;
					r2 = 0;
				}
				if (r1 == 1)
				{
					t++;
					r1 = 0;
				}
				t++;

			}
			cout << t << endl;
		}
	}
	
	return 0;
}