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 <bitset>
  
class Baseball{
    u_int score, out_count;
    std::bitset<4> runners; 
public:
    Baseball() : score(), out_count(){} //initializer list
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() {++out_count;}
    u_int getScore() {return score;}
    u_int getOutcount() {return out_count;}
};
 
void Baseball::hit(){
    runners <<= 1; //shift
	runners.set(0); //set runner
    if(runners.test(3)){
        ++score;
        runners.reset(3);
    }
}
 
void Baseball::homerun(){
    score += runners.count() + 1;
    runners.reset();
}
 
int main(){
    u_int inning;
    std::cin >> inning;
    for(u_int i = 0; i < inning; ++i){
        Baseball game;
        while(game.getOutcount() != 3){
            std::string event;
            std::cin >> event;
            if(event == "HIT"){
                game.hit();
            }
            else if(event == "HOMERUN"){
                game.homerun();
            }
            else if(event == "OUT"){
                game.out();
            }
        }
        std::cout << game.getScore() << std::endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef struct{
    int count;
    string s="OUT";
}OUT;
typedef struct{
    int count;
    string s="HOMERUN";
}HOME;
typedef struct{
    int count;
    string s="HIT";
}HIT;
typedef struct{
    int count;
}RUN;
typedef pair<int, int> pii;
int main(){
    int n; cin>>n;
    pii score=pii(0,0); bool now=1;
    OUT out; HOME home; HIT hit; RUN run;
    out.count=0; home.count=0; hit.count=0; run.count=0;
    string temp;
    while(cin>>temp){
        if(temp==out.s){out.count++; if(out.count==(3*n))goto E;if(out.count%3==0){if(now)now=0; else now=1;run.count=0;}}
        if(temp==home.s){
            if(now)score.first+=run.count+1;
            else score.second+=run.count+1;
            run.count=0;
        }
        if(temp==hit.s){
            run.count++;
            if(run.count>3){if(now)score.first++;else score.second++; run.count-=1;}
        }
    }
E:;cout<<score.first<<"\n"<<score.second<<endl;
}

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

using namespace std;

int main(){
	int n=0,ct=0, score=0, out=0,run=0;
	string x;
	cin >> n;
	while (1){
		int  score = 0, out = 0, run = 0;
		while (1){
			cin >> x;
			if (x == "OUT"){
				out++;
			}
			if (x == "HOMERUN"){
				score+=run;
				score++;
				run = 0;
			}
			if (x == "HIT"){
				run++;
			}
			if (run > 3){
				run--;
				score++;
			}
			if (out == 3){
				cout << score << endl;
				ct++;
				break;
			}
		}
		if (ct == n)break;
	}
	return 0;

}

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

int base[3];
int point = 0;
int out = 0;
int n;

//イニング終わり
void reset_base() {
	for (int i = 0; i < 3; ++i) {
		base[i] = 0;
	}
}

//シングルヒット
void Single_hit() {
	point += base[2];
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
}

//ホームラン
void HomeRun() {
	for (int i = 0; i < 2; ++i) {
		point += base[i];
		base[i] = 0;
	}
	++point;
}

void Out() {
	++out;
	if (out == 3) {
		reset_base();
		out = 0;
		cout << point << endl;
		point = 0;
		--n;
	}
}


int main() {
	cin >> n;
	string s;
	while (n) {
		cin >> s;
		if (s == "HIT") {
			Single_hit();
		}
		else if (s == "HOMERUN") {
			HomeRun();
		}
		else if (s == "OUT") {
			Out();
		}
	}
        return 0;
}

C++: #define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 11
#define HO 6
int main(void)
{
	int n;
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		int out_cou = 0, point = 0;
		bool rui[4] = { 0 };
		while (out_cou < 3) {
			string ev;
			cin >> ev;
			if (ev == "HIT") {
				rui[0] = true;
				for (int i = 3; i >= 1; --i) {
					if (rui[i] == true && i == 3) { ++point; rui[i] = false; }
					if (rui[i - 1] == true) { rui[i] = true; rui[i - 1] = false; }
				}
			}
			else if (ev == "OUT") {
				++out_cou;
			}
			else if (ev == "HOMERUN") {
				for (int i = 1; i < 4; ++i) {
					if (rui[i] == true) { ++point; }
					rui[i] = false;
				}
				++point;
			}
		}
		printf("%d\n", point);
	}
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  int out = 0, base = 0,point = 0;
  int n;
  cin>>n;
  int i=0;
  while(true){
    i++;if(i>20)break;
    string s;
    cin>>s;
    //cout<<s<<endl;
    
    if(s=="OUT"){
      out++;
      //cout<<out<<endl;
      if(out==3){
	//cout<<"poin"<<endl<<endl;;
	cout<<point<<endl;
	point=0;
	out = 0;
	base = 0;
	n--;
	if(n==0)break;
      }
    }
    else if(s=="HIT"){
      base++;
      //cout<<base<<endl;
      if(base>=4){
	//cout<<base<<" "<<point<<endl;
	point++;
	base--;
	//cout<<base<<" "<<point<<endl;
      }
    }
    
    if(s=="HOMERUN"){
      point += base + 1;
      base = 0;
      //cout<<base<<" "<<point<<endl;
		     
    }
    
  }
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;
 
int main(void){
  int out = 0, base = 0,point = 0;
  int n;
  cin>>n;
  int i=0;
  while(true){
    i++;if(i>20)break;
    string s;
    cin>>s;
    //cout<<s<<endl;
     
    if(s=="OUT"){
      out++;
      //cout<<out<<endl;
      if(out==3){
    //cout<<"poin"<<endl<<endl;;
    cout<<point<<endl;
    point=0;
    out = 0;
    base = 0;
    n--;
    if(n==0)break;
      }
    }
    else if(s=="HIT"){
      base++;
      //cout<<base<<endl;
      if(base>=4){
    //cout<<base<<" "<<point<<endl;
    point++;
    base--;
    //cout<<base<<" "<<point<<endl;
      }
    }
     
    if(s=="HOMERUN"){
      point += base+1;
      base = 0;
              
    }
     
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[4]={0},k=0,l=0;
  string s;
  cin>>n;
  while(k!=n){
    cin>>s;
    if(s=="HIT"){
      if(!a[0])a[0]++;
      else {
        if(!a[1])a[1]++;
        else{
          if(!a[2])a[2]++;
          else a[3]++;
        }
      }
    }
    else if(s=="OUT"){
      l++;
      if(l==3){
        a[1]=a[2]=a[0]=l=0;
        k++;
      }
    }
    else{
    a[3]+=1+a[1]+a[2]+a[0];
    a[1]=a[2]=a[0]=0;
    }
  }
  cout<<a[3]<<endl;
}