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 <iostream>
#include <string>
using namespace std;

int main() {
	string str;
	bool first = false, second = false, third = false;
	int out = 0, points = 0;
	int n;

	cin >> n;
	for(int i = 0; i < n;) {
		cin >> str;

		if(str == "HIT") {
			if(third == true)
				points++;

			third = second;
			second = first;
			first = true;
		}

		else if(str == "OUT") {
			out++;
			if(out == 3) {
				out = 0;
				first = second = third = false;
				cout << points << endl;
				points = 0;
				i++;
				continue;
			}
		}

		else if(str == "HOMERUN") {
			points++;
			if(first) points++;
			if(second) points++;
			if(third) points++;
			first = second = third = false;
		}
	}
}

C++: #include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
    int n, o, h, t;
    string s;
    cin >> n;
     
    while(n--)
{
        o = h = t = 0;
        while(o < 3)
{
            cin >> s;
            if(s == "HIT")
{
                if(h == 3)
{
                    t++;
                } 
else 
{
                    h++;
                }
            } 
else if(s == "HOMERUN")
{
                t = t + h + 1;
                h = 0;
            } 
else 
{
                o++;
            }
        }
        cout << t << endl;
    }
     
    return 0;
}

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

int main() {

  int n;
  cin >> n;
  int outcnt = 0;
  int game = 0;
  int base = 0;
  int score = 0;
  while(1) {
    if(game == n) break;
    string str;
    cin >> str;
    if(str == "OUT") outcnt++;
    if(outcnt == 3) {
      cout << score <<endl;
      game++;
      outcnt = base = score = 0;
      continue;
    }
    if(str == "HIT") {
      base++;
      if(base == 4) score++,base--;
    }
    if(str == "HOMERUN") {
      score += base+1;
      base = 0;
    }

  }

  return 0;
}

C++: #include <iostream>

using namespace std;

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

  while (n--) {
    bool base[3] = {false, false, false};
    int out = 0;
    int point = 0;
    char c[8];

    while (out < 3) {
      cin >> c;

      if (c[0] == 'O')  out++;
      if (c[0] == 'H')
        if (c[1] == 'I') {
          for (int i = 0; i < 3; i++) {
            if (!base[i]) {
              base[i] = true;
              break;
            } else if (i == 2) {
              point++;
            }
          }
        } else {
          for (auto& b : base) {
            if (b) {
              point++;
              b = false;
            }
          }
          point++;
        }
    }
    cout << point << endl;
  }
}

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

using namespace std;


#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 MOD 1000000007

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;cin>>n;
  for(int i=0;i<n;i++){
      int f=0,s=0,t=0,out=0,point=0;
      string st;
      while(cin>>st){
          if(st=="HIT"){
              if(t) point++;
              if(s) t=1;
              if(f) s=1;
              f=1;
          }
          else if(st=="HOMERUN"){
              point+=(f+s+t+1);
              f=0;s=0;t=0;
          }
          else{
              out++;
              if(out==3){
                  cout<<point<<endl;
                  break;
              }
          }
      }
  }
  
}

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

int Baseball()
{
    int num_of_runner = 0, num_of_out = 0, point = 0;
    std::string event;
    while(num_of_out != 3){
        std::cin >> event;
        if(event == HIT){
            if(num_of_runner == 3)
                ++point;
            else
                ++num_of_runner;
        }
        else if(evenr == HOMERUN){
            point += 1 + num_of_runner;
            num_of_runner = 0;
        }
        else
            ++num_of_out;
    }
    
    return point;
}

int main()
{
    u_int num_of_inning;
    std::cin >> num_of_inning;
    
    for(u_int i = 0; i < num_of_inning; ++i){
        std::cout << Baseball() << std::endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
string a;
int n,o,r[3],run,ans;
int main() {
        cin>>n;
    for(int loop=0;loop<n;loop++){
        for(int i=0;i<3;i++)r[i]=0;
        o=0;ans=0;run=0;
        while(o<3){
            cin>>a;
            if(a=="HOMERUN"){
                ans+=(run+1);
                run=0;
                for(int i=0;i<3;i++)r[i]=0;
            }if(a=="HIT"){
                if(r[2]==1){
                    r[2]=0;
                    ans++;
                    run--;
                }
                if(r[1]==1){
                    r[1]=0;r[2]=1;
                }
                if(r[0]==1){
                    r[0]=0;r[1]=1;
                }
                r[0]=1;run++;
            }else if(a=="OUT"){
               o++;
            }   
        }
        cout<<ans<<endl;
    }
        return 0;
}

C++: #include <stdio.h>

int main() {
    int T;
    char op[16];
    scanf("%d", &T);
    while (T--) {
        int out = 0, r = 0, p = 0;
        while (out < 3) {
            scanf("%s", op);
            if (op[0] == 'O') out++;
            else if (op[1] == 'O') { p += r+1; r = 0; }
            else if (op[1] == 'I') { r++; if (r == 4) r--, p++; }
        }
        printf("%d\n", p);
    }
    return 0;
}

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

class Baseball{
private:
	int runner; // 0~3: the number of runner
	int out_count; //0~2: out count
	int point;

public:
	Baseball(){
		runner = 0;
		out_count = 0;
		point = 0;
	}

	bool judge(std::string event){
		if(event == "HIT"){
			return single_hit();
		}else if(event == "HOMERUN"){
			return home_run();
		}else{
			return out();
		}
	}

	void display(){
		std::cout << point << std::endl;
	}

	bool single_hit(){
		(runner == 3) ? ++point : ++runner;
		return 1;
	}

	bool home_run(){
		point = point + runner + 1;
		runner = 0;
		return 1;
	}

	bool out(){
		if(out_count == 2){
			display();
			return 0;
		}else{
			++out_count;
			return 1;
		}
	}
};

int main(){
	int n; // the number of datasets
	std::cin >> n;

	for(int i = 0; i < n; ++i){
		Baseball inning;
		std::string eve;
		std::cin >> eve;
		while(inning.judge(eve) == 1){
			std::cin >> eve;
		}
	}
	return 0;
}

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

int main()
{
	int point, base, n, out;
	char ibe[10];

	cin >> n;
	for (int k = 0; k < n; k++){
		base = point = out = 0;
		while (out != 3){
	 	 cin >> ibe;
		 if (ibe == "HIT"){
			 base++;
			 if (base == 4){
				 base--;
				 point++;
			 }
		 }
		 else if (ibe == "HOMERUN"){
			 point += base;
			 base = 0;
		 }
		 else {
			 out++;
		 }
		}
		cout << point << endl;
	}
	return (0);
}