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>
#include<cstring>
using namespace std;
int x[4], n, cnt; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++){
		memset(x, 0, 16);
		while (true) {
			cin >> S;
			if (S == "HIT") {
				x[0] += x[3]; x[3] = 0;
				x[3] += x[2]; x[2] = 0;
				x[2] += x[1]; x[1] = 0;
				x[1] += 1;
			}
			if (S == "OUT") {
				cnt++; if (cnt % 3 == 0) { goto E; }
			}
			if (S == "HOMERUN") {
				x[0] += x[3] + x[2] + x[1] + 1;
				x[3] = 0; x[2] = 0; x[1] = 0;
			}
		}
	E:;
		cout << x[0] << endl;
	}
}

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(baseball.get_out() != 3){
			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();

		}

		std::cout >> baseball.get_point() >> std::endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){

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

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    for (int _ = 0; _ < n; ++_) {
        int outs = 0, score = 0, a = 0, b = 0, c = 0;
        while(outs < 3){
            string s;
            cin >> s;
            if(s == "HIT"){
                score += c; c = b; b = a; a = 1;
            }else if(s == "HOMERUN"){
                score += a+b+c+1; a = b = c = 0;
            }else {
                outs++;
            }
        }
        cout << score << "\n";
    }
    return 0;
}

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

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner;
	
	public:
	
	Baseball(){
		out_count = 0;
		for(int i=0; i<4; ++i)
			runner[i] = 0;
	}
	
	void ining(){
		while(out_count != 3){
			std::string str;
			std::getline(std::cin, str);
		
			if(str == "HIT")
				hit();
			else if(str == "OUT")
				out();
			else homerun();
		}
		
		std::cout << runner[3] << std::endl;
		return;
	}
	
	void hit(){
		int i;
		for(i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
		}
		++runner[i];
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
		++runner[3];
	}
};

int main(){
	int n;
	std::cin >> n;
	
	for(int k=0; k<n; ++k){
		Baseball game;
		game.ining();
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    int t; cin>>t;
    REP(kai,t){
        int out=0;
        int point=0;
        bool rui[3]={false,false,false};
        while(true){
            string s; cin>>s;
            if(s=="OUT"){
                out++;
                if(out==3)goto nextf;
            }else if(s=="HOMERUN"){
                point++;
                REP(j,3)if(rui[j])point++;
                REP(j,3)rui[j]=false;
            }else{
                if(rui[2])point++;
                rui[2]=rui[1];
                rui[1]=rui[0];
                rui[0]=true;
            }
        }
    nextf:;
        cout<<point<<endl;
    }
    
    return 0;
}

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

int main(){
	int b1,b2,b3,s,o,n;
	string c;
	cin>>n;
	for(int i=0;i<n;i++){
		b1=0;b2=0;b3=0;s=0;o=0;
		while(o<3){
			cin>>c;
			if(c=="HIT"){
				if(b3){s++;b3=0;}
				if(b2){b3=1;b2=0;}
				if(b1)b2=1;
				b1=1;
			}
			else if(c=="HOMERUN"){
				if(b1&&b2&&b3)s+=4;
				else if(b1&&b2||b2&&b3||b3&&b1)s+=3;
				else if(b1||b2||b3)s+=2;
				else s++;
				b1=0;b2=0;b3=0;
			}
			else o++;
		}
		cout<<s<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstring>
using namespace std;
int x[4], n, cnt; string S;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++){
		while (true) {
			memset(x, 0, 16);
			cin >> S;
			if (S == "HIT") {
				x[0] += x[3]; x[3] = 0;
				x[3] += x[2]; x[2] = 0;
				x[2] += x[1]; x[1] = 0;
				x[1] += 1;
			}
			if (S == "OUT") {
				cnt++; if (cnt % 3 == 0) { goto E; }
			}
			if (S == "HOMERUN") {
				x[0] += x[3] + x[2] + x[1] + 1;
				x[3] = 0; x[2] = 0; x[1] = 0; x[0] = 0;
			}
		}
	E:;
		cout << x[0] << endl;
	}
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n,i=0,out=0,g=0;
	int cange=0,score[2]={0,0};
	char evn[100][7];
	int base[4]={0,0,0,0};
	cin >> n;
	while(n!=g){
		cin >> evn[i];
		if(evn[i][1]=='I'){
			base[3]+=base[2];
			base[2]=base[1];
			base[1]=base[0];
			base[0]=1;
		}
		if(evn[i][1]=='O'){
			base[3]+=base[2]+base[1]+base[0]+1;
			base[2]=0;
			base[1]=0;
			base[0]=0;
		}
		if(evn[i][0]=='O'){
			out++;
		}
		if(out==3){
			out=0;
			base[0]=0;
			base[1]=0;
			base[2]=0;
			if(cange==0){
				score[0]=base[3];
				base[3]=0;
				cange=1;
				g++;
			}
			else{
				score[1]=base[3];
				base[3]=0;
				cange=0;
				g++;
			}
		}
	}
	cout << score[0] << endl <<score[1] << endl;
return 0;
}