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 <queue>
#include <string>

class Baseball{
    private:
        std::queue<int> runner;
        int out_count;
        int score;
        
    public:
        void initRunner(){
            while(runner.empty() != true){
                runner.pop();
            }
            for(int i = 0; i < 3; ++i){
                runner.push(0);
            }
        }
        
        Baseball(){
            out_count = 0;
            score = 0;
            initRunner();
        }
        
        ~Baseball(){}
        
        void hit(){
            if(runner.back() == 1) ++score;
            runner.pop();
            runner.push(1);
        }
        
        void homerun(){
            do{
                if(runner.back() == 1) ++score;
                runner.pop();
            } while(runner.empty() != true);
            ++score;
            initRunner();
        }
        
        int getScore(){
            initRunner();
            std::string str;
            while(out_count != 3){
                std::cin >> str;
                if(str == "HIT") hit();
                if(str == "HOMERUN") homerun();
                if(str == "OUT") ++out_count;
            }
            return score;
        }
};

int main(void){
    int N;
    std::cin >> N;
    for(int i = 0; i < N; ++i){
        Baseball baseball;
        std::cout << baseball.getScore() << std::endl;
    }
}

C++: #include<stdio.h>
#include<string.h>

int main(){

    int i,j,n;
    int out=0;
    char s[10];
    scanf("%d", &n);
    if(n!=0){
      int base[4]={};
      while(n>0){
	if(out<3){
	  scanf("%s", s);
	  if(strcmp(s, "HIT") ==0)
	    {base[3]+=base[2];base[2]=base[1];base[1]=base[0];base[0]=1;}
	  if(strcmp(s, "HOMERUN") ==0)
	    {base[3]=base[3]+base[2]+base[1]+base[0]+1;base[0]=0;base[1]=0;base[2]=0;}
	  if(strcmp(s, "OUT") ==0)
	    out++;
	  //printf("%d %d %d %d\n", base[0], base[1], base[2], base[3]);
	}
	else
	  {out=0;printf("%d\n", base[3]);n--;base[0]=0;base[1]=0;base[2]=0;base[3]=0;}
      }
    }
  return 0;
}

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

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

	public:
	void init();
	int get_out();
	int get_point();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::init(){
	out = 0;
	runner = 0;
	point = 0;
}

int Baseball::get_out(){
	return out;	
}

int Baseball::get_point(){
	return point;
}

void Baseball::event_hit(){
	if(runner == 3){
		++point;
	}else{
		++runner;
	}
}

void Baseball::event_homerun(){
	point += ++runner;
}

void Baseball::event_out(){
	++out;
}

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	Baseball base;
	base.init();
	for(int i = 0; i < num; ++i){
		while(base.get_out() < 3){
			std:: cin >> event;

			if(event == "OUT"){
				base.event_out();		
			}else if(event == "HIT"){
				base.event_hit();
			}else if(event == "HOMERUN"){
				base.event_homerun();
			}
		}
		std::cout << base.get_point() << std::endl;
		base.init();
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(void)
{
	int base=0,out=0,score=0,e,i,j;
	char str[10];
	for(;;){
		scanf("%d",&e);
		if(e==0)break;
		for(i=0;i<e;){
			scanf("%s",&str);
			if(!strcmp(str,"HIT"))base++;
			
			else if(!strcmp(str,"OUT")){
				out++;
			}
			
			else if(!strcmp(str,"HOMERUN")){
				score=score+base+1;
				base=0;
			}
			if(base>3){
				base--;
				score++;
			}
			if(out==3){
				out=0;
				printf("%d\n",score);
				i++;
				base=0;
				score=0;
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll Q; cin >> Q;
    while ( Q-- ) {
        ll rest = 3;
        vector<bool> state(3, false);
        ll ans = 0;
        while (rest) {
            string s; cin >> s;
            if (s == "HIT") {
                ans += state[2];
                RREP(i, 2) state[i+1] = state[i];
                state[0] = true;
            }
            else if (s == "OUT") {
                --rest;
            }
            else {
                REP(i, 3) {
                    ans += state[i];
                    state[i] = false;
                }
                ++ans;
            }
        }
        cout << ans << endl;
    }
}

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

using namespace std;

int main()
{
	int i,n,point=0;
	bool run[3];
	string s;
	cin >> n;
	int out=3;
	while(n--){
		for(i=0;i<3;i++) run[i]=0;
		point=0;
		out=3;
		while(out){
			cin >> s;
			if(s == "HIT"){
				if(run[2])point++;
				for(i=2;i>0;i--) run[i]=run[i-1];
				run[0]=1;
				}
				else if(s == "HOMERUN"){	for(i=0;i>3;i++) if(run[i]){ point++; run[i]=0;} point++;}
				else out--;
		}
	cout << point << "\n";
	}
	return 0;
}

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

int main(){
	bool F,S,T;
	int out,point;
	
	int i,j;
	
	int dataN,dataLoop;
	string E;
	
	cin>>dataN;
	for(dataLoop=0;dataLoop<dataN;dataLoop++){
	out=0;point=0;
	F=false;S=false;T=false;
	while(out!=3){
	 cin>>E;
	 if(E=="HIT"){
	  if(T){point++;}
	  T=S;S=F;F=true;
	 }else if(E=="HOMERUN"){
	  point++;
	  if(F){point++;F=false;}
	  if(S){point++;S=false;}
	  if(T){point++;T=false;}
	 }else{
	  out++;
	 }
	}
	cout<<point<<endl;
	}
	
	return 0;
}

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

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

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT")
				baseball.add_out();
			
			if(baseball.get_out() == 3){
				int P = baseball.get_point();
				std::cout >> P >> std::endl;
				break;
			}
		}

	}

	return 0;
}