Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

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;
	REP(j,n) {
		int out = 0, score = 0;
		vi v(3, 0);
		while (out <3) {
			string s;
			cin >> s;
			if (s == "HIT") {
				RREP(i, 3) {
					if (v[i] == 1) {
						if (i == 2)score++;
						else v[i + 1]++;
						v[i]--;

					}
				}
				v[0]++;
			}
			else if (s[0] == 'O') {
				out++;
			}
			else {
				REP(i, 3) {
					if (v[i] == 1) {
						score++;
						v[i] = 0;
					}
				}
				score++;
			}
		}
		cout << score << endl;
	}
	return 0;
}

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;
}