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;

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

C++: #include <iostream>
#include <string>
using namespace std;
int main(void){
	int n;
	for(int i=0; i<n; i++){
		int out=0,base=0,point=0;
		while(out<3){
			string event;
			cin >> event;
			if(event == "OUT"){
				out++;
			}else if(event == "HIT"){
				if(base == 3){
					point++;
				}else{
					base++;
				}
			}else{
				point += base + 1;
				base = 0;
			}
		}
		cout << point << endl;
	}
	return 0;
}

C++: #include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

void hit(int base[], int& score){
	if(base[2] == 1){
		score++;
		base[2] = 0;
	}
	if(base[1] == 1){
		base[2] = 1, base[1] = 0;
	}
	if(base[0] == 1){
		base[1] = 1;
	}
	base[0] = 1;

	return ;
}

void homerun(int base[], int& score){
	score += base[0] + base[1] + base[2] + 1;
	base[0] = base[1] = base[2] = 0;
	return ;
}

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

	for(int i=0; i<n; ++i){
		int score = 0, out = 0;
		int base[3] = {0};
		string s;
		while(1){
			cin >> s;
			if(s == "HIT")
				hit(base, score);
			if(s == "HOMERUN")
				homerun(base, score);
			if(s == "OUT"){
				out++;
				if(out == 3){
					cout << score << endl;
					break;
				}
			}
		}
	}


	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,ground,ou,point;
  string s;
  
  scanf("%d",&n);
  
  for(int cas=0;cas<n;cas++){
    ground = ou = point = 0;
    while(1){
      cin >> s;
      if(s == "OUT"){
	ou++;
	if(ou == 3) break;
      } else if(s == "HIT"){
	ground<<=1;
	ground|=1;
	if(ground >= (1<<3)){
	  ground&=(~(1<<3));
	  point++;
	}
      } else{
	for(int i=0;i<3;i++){
	  if(ground&(1<<i)) point++;
	}
	ground=0;
	point++;
      }
    }
    cout << point << endl;
  }
  
  return 0;
}

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

int main()
{
	int n,inning=0;
	int p[40] = {0};
	string ivent;

	cin >> n ;
	while (1)
	{
		int r=0, o=3;                        //r = ???????????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p[inning]++;
                                        r=3;
				}
			}

			else if (ivent=="HORMRUN")
			{
				p[inning] += r + 1;
				r = 0;                            //??????????????????????????????
			}
			else if (ivent=="OUT")
			{
				o--;
			}
		}
		cout << p[inning] << endl;
		inning++;
		if (n == inning) break;

	}

	return 0;
}