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

using namespace std;


int main(){
  int n;
  string event;
  int base=0;
  int inning=0;
  cin>>n;
  vector<int> point(n);
  int outnum=0;
  while(inning<n){
    cin>>event;
    if(event=="HIT"){
      base<<=1;
      base|=1;
      if(base&8){
        point[inning]++;
        base^=8;
      }
    }else if(event=="HOMERUN"){
      point[inning]+=1;
      for(int i=0;i<3;i++)
        point[inning]+=(base>>i)&1;
      base=0;
    }else if(event=="OUT"){
      outnum++;
      if(outnum>2){
        outnum=0;
        inning++;
        base=0;
      }
    }
  }
  for(int p:point)
    cout<<p<<endl;
}

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

class Baseball{
public:
    Baseball();
    void init();
    int getPoint();
    void hit();
    void homerun();
    // @return false - the inning ends.
    bool out();
    
private:
    int point;
    unsigned int outs;
    bool base[3];
};

Baseball::Baseball(){
    init();
}

void Baseball::init(){
    point = 0;
    outs = 0;
    for (int i=0; i<3; ++i) {
        base[i] = false;
    }
}

inline int Baseball::getPoint(){
    return point;
}

void Baseball::hit(){
    if (base[2]) {
        ++point;
    }
    for (int i=2; i>0; --i) {
        base[i] = base[i-1];
    }
    base[0] = true;
}

void Baseball::homerun(){
    ++point;    // batter's point
    // runner's point
    for (int i=0; i<3; ++i) {
        if (base[i]) {
            ++point;
        }
    }
    
    for (int i=0; i<3; ++i) {
        base[i] = false;
    }
}

bool Baseball::out(){
    ++outs;
    if (outs > 2) {
        return false;
    }else{
        return true;
    }
}


int main(){
    int n;  // number of data sets
    
    std::cin >> n;
    
    for (int i=0; i<n; ++i) {
        Baseball inning;
        std::string str;
        
        while (true) {
            std::getline(std::cin,str);
            if (str=="HIT"){
                inning.hit();
            }
            else if (str=="HOMERUN"){
                inning.homerun();
                
            }
            else if (str=="OUT"){
                if (!inning.out()) {
                    break;
                }
            }
        }
        
        // output
        std::cout << inning.getPoint() << std::endl;
    }
    
    return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0103&lang=jp
//1003ð~XéöxÌâèÍ

#include<iostream>
#include<string>
using namespace std;

int main(void){
     int atotal=0,btotal=0;
     int out=0;
     int n=0;
     bool one=false,two=false,three=false;
     string move="";
     cin >> n;
     for(int i=0;i<n;i++){
	  out = 0;
	  one=false;
	  two=false;
	  three=false;
	  atotal = 0;
	  btotal = 0;
	  do{
	       cin >> move;
	       if(move == "HIT"){
		    bool home;
		    home = three;
		    three = two;
		    two = one;
		    one = true;
		    if(home == true){
			 if(i%2 == 0){
			      atotal++;
			 }else{
			      btotal++;
			 }
		    }
		    // cout << "HIT" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;;
		    // cout << " " << endl;
	       }
	       if(move == "OUT"){
		    out++;
		    // cout << "OUT" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;
		    // cout << " " << endl;
	       }
	       if(move == "HOMERUN"){
		    if(i%2 == 0){
			 int t = 1;
			 if(one == true){
			      one = false;
			      t++;
			 }
			 if(two == true){
			      two = false;
			      t++;
			 }
			 if(three == true){
			      three = false;
			      t++;
			 }
			 atotal = atotal+t;
		    }else{
			  int t = 1;
			 if(one == true){
			      one = false;
			      t++;
			 }
			 if(two == true){
			      two = false;
			      t++;
			 }
			 if(three == true){
			      three = false;
			      t++;
			 }
			 btotal = btotal + t;
		    }
		    // cout << "z[" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;
		    // cout << " " << endl;
	       }
	  }while(out < 3);
	  if(i%2 == 0){
	       cout << atotal << endl;
	  }else{
	       cout << btotal << endl;
	  }
     }
     return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
using namespace std;
int main(){
int n;
cin>>n;
rep(i,n){
int out=0;
int r1=0,r2=0,r3=0;
int tm=0;
while(out!=3){
char in[10];
cin>>in;
if(strcmp(in,"OUT")==0)out++;
if(strcmp(in,"HIT")==0){
if(r3==1){tm++;r3=0;}
if(r2==1){r3=1;r2=0;}
if(r1==1){r2=1;r1=0;}
r1++;
}
if(strcmp(in,"HOMERUN")==0){
if(r1==1){tm++;r1=0;}
if(r2==1){tm++;r2=0;}
if(r3==1){tm++;r3=0;}
tm++;
}
}
cout<<tm<<endl;
}
}

C++: #include<stdio.h>

int main(){
	int c,y,t,o,p;
	char a[9];
	scanf("%d",&c);
	for(y=0;y<c;y++){
		t=o=p=0;
		while(1){
			scanf("%s",&a);
			if(a[0]=='H')t++;
			if(a[0]=='O')o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}
}

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>
using namespace std;

int main(){
  int x;
  cin>>x;
  string s;
  string h="HIT";
  string home="HOMERUN";
  string o="OUT";
  
  for(int j=0;j<x;j++){
    int count=0;
    int point=0;
    int r=0;

 
    for(int i=0;i<100;i++){
      cin>>s;
 
      if(s==h){
	r++;
	if(r==4){
	  point++;
	  r--;
	}
      }

      if(s==home){
	point++;
	point+=r;
	r=0;
      }

      if(s==o){
	count++;
	if(count==3)break;
      }
    }
      cout<<point<<endl;

    
  }
  }

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  cin>>n;
  rep(i,n){
    int out=0,point=0;
    int run[3]={};
    string s;
    int F=0,S=0,T=0;
    while(out!=3){
      cin>>s;
      if(s=="OUT")out++;
      else if(s=="HOMERUN"){
        rep(i,3){
          point+=run[i];
          run[i]=0;
        }
        point++;
      }else{
        if(run[2]==1)point++;
        for(int i=2;i>=0;i--)run[i]=run[i-1];
        run[0]=1;
      }
    }
    cout<<point<<endl;
  }
  return 0;
}