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<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n,i=0,out=0,g=0;
	int cange=0,score[2]={0,0};
	char evn[100][7];
	int base[4]={0,0,0,0};
	cin >> n;
	while(n!=g){
		cin >> evn[i];
		if(evn[i][1]=='I'){
			base[3]+=base[2];
			base[2]=base[1];
			base[1]=base[0];
			base[0]=1;
		}
		if(evn[i][1]=='O'){
			base[3]+=base[2]+base[1]+base[0]+1;
			base[2]=0;base[1]=0;base[0]=0;
		}
		if(evn[i][0]=='O'){
			out++;
		}
		if(out==3){
			out=0;
			base[0]=0;
			base[1]=0;
			base[2]=0;
			if(cange==0){
			score[0]=base[3];
			base[3]=0;
			cange=1;
			g++;
			}
			else{
				score[1]=base[3];
				score[3]=0;
				cange=0;
				g++;
			}
		}
	}
	cout << score[0] << endl <<score[1];
return 0;
}

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i, n) {
		int base[3];
		int cnt = 0;
		int out = 0;
		rep(i123, 3) { base[i123] = 0; }
		while (true) {
			string thistime;
			cin >> thistime;
			if (thistime == "HIT") {
				cnt += base[2];
				base[2] = base[1];
				base[1] = base[0];
				base[0]=1;
			}
			else if (thistime == "OUT") {
				out++;
				if (out == 3) { break; }
			}
			else {
				cnt += base[2] + base[1] + base[0] + 1;
				base[2] = base[1] = base[0] = 0;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

int main(){
  int n;
  cin>>n;
  while(n--){
    int score = 0;
    int out = 0;
    bool r1,r2,r3;
    r1=r2=r3=false;
    while(true){
      string s;
      cin>>s;
      if(s=="HIT"){
        if(r3)r3=false,++score;
        if(r2)r2=false,r3=true;
        if(r1)r1=false,r2=true;
        r1=true;
      }else if(s=="HOMERUN"){
        score += r1;
        score += r2;
        score += r3;
        score += 1;
        r1=r2=r3=false;
      }else if(s=="OUT"){
        ++out;
        if(out==3)break;
      }
    }
    cout<<score<<endl;
  }
  return 0;
}

C++: #include <cstring>
#include <deque>
#include <iostream>

using namespace std;

int main() {

	int n;

	cin >> n;

	while(n) {
		int o=0, s=0;
			char c[8];
		deque<int> b;
		while(o!=3) {
			cin >> c;
			if((strstr(c, "HIT")!=NULL)) {
				b.push_back(1);
				if(b.size()==4) {
					s++;
					b.pop_back();
				}
			}
			else if((strstr(c, "HOMERUN")!=NULL)) {
				s+=1+b.size();
				b.clear();
			}
			else if((strstr(c, "OUT")!=NULL)) {
				o++;
			}
		}
		cout << s << endl;
		n--;
	}

	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 += 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<bits/stdc++.h>
using namespace std;

int main() {

  int n;
  cin >> n;
  while( n-- ) {
    int score = 0, out = 0;
    int base[4] = {0};

    while(1) {      
      if( out == 3 ) {
	cout << score << endl;
	break;;
      }
      
      string event;
      cin >> event;
      if( event == "HIT" ) {
	if( base[3] ) {
	  score++;
	  base[3] = 0;
	}
	if( base[2] ) {
	  base[3] = 1;
	  base[2] = 0;
	}
	if( base[1] ) {
	  base[2] = 1;
	  base[1] = 0;
	}
	base[1] = 1;
      }
      
      else if( event == "HOMERUN" ) {
	score += base[3]+base[2]+base[1]+1;
	base[3] = base[2] = base[1] = 0;
      }
      
      else {
	out++;
      }
    }
  }
}

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

using namespace std;

int main(){
        string t;
        int i,r,score,o,ini;
        score = 0;
        cin >> ini;
        for(i=0;i<ini;i++){
        while(1){
        cin >> t;
        if(t == "HIT"){
                r++;
                if(r == 4){
                        score++;
                        r--;
                }
        }else if(t == "OUT"){
                o++;
                if(o == 3){
                        r = o = 0;
                        break;
                }
        }else if(t == "HOMERUN"){
                score += r + 1;
                r = 0;
        }
        }
        cout << score << endl;
        }
return 0;
}