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"

using namespace std;

int main (){
	int n;
	cin >> n;

	for(int i = 1;i <= n;i++){
		int h = 0;
		int o = 0;
		int sc = 0;
		string a;
	while(1){
		cin >> a;
		if(a == "HIT"){
			h++;
		}
		if(a == "OUT"){
			o++;
		}
		if(a == "HOMERUN"){
			sc = sc + h + 1;
			h = 0;
		}
		if(o == 3) break;
		if(h == 4){
			sc++;
			h--;
		}
	}
		cout << sc <<endl;
	}



	return 0;
}

C++: #include <iostream>
using namespace std;
void inning() {
  int out = 0, runner = 0, score = 0;
  string ev;
  while(out < 3) {
	cin >> ev;
	if(ev == "OUT") {
	  out++;
	  if(out == 3) {
		cout << score << endl;
		return;
	  }
	}
	else if(ev == "HOMERUN") {
	  score += runner + 1;
	  runner = 0;
	}
	else {// hit
	  if(runner == 3) score++;
	  else runner++;
	}
  }
}
int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++n) {
	inning();
  }

  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long n,r,p,o,i;
string s;
cin>>n;
for(i=0;i<n;i++){
o=p=r=0;
while(cin>>s){
if(s=="HIT"){
r*=2;r++;if(r>=8){p++;r-=8;}
}else if(s=="HOMERUN"){
if(r==0)p++;
else if(r==1||r==2||r==4)p+=2;
else if(r==3||r==5||r==6)p+=3;
else if(r==7)p+=4;
r=0;
}else if(s=="OUT"){
o++;
if(o>=3)break;
}
}
cout<<p<<endl;
}
return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  int out=0,b=0,p= 0;
  while(cin >> s){
    if(s == "OUT" && out == 2){
      out = 0;
      b = 0;
      n--;
      cout << p << endl;
      p = 0;
      // if(n == 0)  break;
    } 
    if(s == "OUT") out++;
    if(s == "HIT"){
      if(b == 3 ) p++;
      else b++;
    }
    if(s == "HOMERUN"){
      p += b + 1;
      b = 0;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <bitset>

#define First 0x01
#define Second 0x01 << 1
#define Third 0x01 << 2
#define Run 0x01 << 3

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string str;
		int out = 0, score = 0;
		unsigned field = 0;
		while (out < 3) {
			cin >> str;
			if (str == "HIT") {
				field = field << 1;
				field |= First;
				if (field & Run) {
					score++;
					field &= ~(Run);
				}
			}
			else if (str == "HOMERUN") {
				score++;
				if (field & First) score++;
				if (field & Second) score++;
				if (field & Third) score++;
				field = 0;
			}
			else if (str == "OUT") {
				out++;
			}
			cout << bitset<8>(field) << endl;
		}
		cout << score << endl;
	}
	return 0;
}

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

int main(){
    int i;
    int n;
    cin >> n;
    int base[3]={0};
    int nout=0;
    int point=0;
    string HIT("HIT");
    string HOMERUN("HOMERUN");
    string OUT("OUT");
    while(n--){
        for(i=0;i<3;i++){
            base[i]=0;
        }
        nout=0;
        point=0;
        while(nout!=3){
            string str;
            cin >> str;
            if(str == HIT){
                for(i=2;i>=0;i--){
                    if(i==2){
                        point += base[i];
                    }
                    if(i!=0){
                        base[i]=0;
                        base[i] += base[i-1];
                    }else{
                        base[i] = 1;
                    }
                }
            }
            if(str == HOMERUN){
                for(i=0;i<3;i++){
                    point += base[i];
                    base[i] = 0;
                }
                point++;
            }
            if(str == OUT){
                nout++;
            }
        }
        cout << point << endl;
    }
    return 0;
}

C++: #include <iostream>

class Baseball{
private:
	int score,out,runner,inning;
public:
    Baseball();
    ~Baseball()=default;
    void checkEvent(std::string event);
    void hit();
    void homerun();
    void countOut();
    int getInning();
};

Baseball::Baseball(){
	score=0,out=0,runner=0,inning=0;
}

void Baseball::checkEvent(std::string event){
    if(event=="HIT"){
        this->hit();
    }
    else if(event=="OUT"){
        this->countOut();
    }
    else if(event=="HOMERUN"){
        this->homerun();
    }
}

void Baseball::hit(){
	runner<3?++runner:++score;
}
	
void Baseball::countOut(){
	if(out<2){
		++out;
	}
	else{
	std::cout << score << std::endl;
	runner=0,out=0,score=0;++inning;
	}
}
	
void Baseball::homerun(){
	score+=runner+1;
	runner=0;
}	

int Baseball::getInning(){
	return inning;
}

int main() {
	Baseball game;
	int num;
	std::cin >> num;
	while(game.getInning()<num){
		std::string event;
		std::cin >> event;
		game.checkEvent(event);
	}
	return 0;
}

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

int main(void){
	int dataset,ining;
	int i;
	int runner[3],point,out;
	char str[8];

	scanf("%d",&dataset);
	for(ining=0;ining<dataset;ining++){

		//init state variable
		for(i=0;i<3;i++){
			runner[i]=0;
		}
		point=0;
		out=0;

		//start	ining
		while(out<3){
			scanf("%s",&str[0]);

			if(strcmp(str,"HOMERUN")==0){
		                for(i=0;i<3;i++){
					point+=runner[i];
		                        runner[i]=0;
		                }
				point++;
			}

			else if(strcmp(str,"HIT")==0){
				if(runner[2]==1){
					runner[2]=0;
					point++;
				}
				if(runner[1]==1){
					runner[1]=0;
					runner[2]=1;
				}
				if(runner[0]==1){
					runner[0]=0;
					runner[1]=1;
				}
				runner[0]=1;
			}

			else if(strcmp(str,"OUT")==0){
				out++;
			}
			printf("POINT:%d OUT:%d\n",point,out);
		}

		//finish ining
		printf("%d\n",point);
	}
}

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

int main()
{
	bool base[4];
	int out;
	int n;
	int score;
	std::string event;

	std::cin>>n;
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<4;i++)base[i]=0;
		out=0;
		score=0;
		while(out<3)
		{
			std::cin>>event;
			if(event=="HIT")
			{
				for(int i=2;i>=0;i--)
				{
					base[i+1]=base[i];
				}
				base[0]=true;
				if(base[3]==true)
				{
					score++;
					base[3]=false;
				}
			}
			else if(event=="HOMERUN")
			{
				for(int i=2;i>=0;i--)
				{
					if(base[i])
					{
						score++;
						base[i]=false;
					}
				}
				score++;
			}
			else if(event=="OUT")
			{
				out++;
			}
		}
		std::cout<<score<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;

int main(){
  int n;
  cin >> n;
  while(n--){
    int out = 0, score = 0, runner = 0;
    while(out<3){
      string s;
      cin >> s;
      if(s == "HIT"){
    runner++;
    if(runner == 4){
      score++; runner--;
    }
      }else if(s == "HOMERUN"){
    score += runner+1;
    runner = 0;
      }else{
    out++;
      }
    }
    cout << score << endl;
  }
}