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>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<string> a(101);
    bool run[30]={false, false, false};
    int out=0, e=0;
    int point[500] = {};
    int j=0;
    int k=0;
    while(cin >> a[j]) {
        if(a[j]=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a[j]=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        j++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }
 
}

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

using namespace std;

int main(){
	int n , i = 1;
	int base = 0 , sum[3] = {} , out_count = 0;
	string str;

	cin >> n;
		
	while(1){
	    
		if(i > n) break;
		cin >> str;
		
		if(out_count >= 3){
			base = 0;
			i++;
		}
		if(base >= 4){
		    sum[i]++;
		    base = base - 1;
		}
		if(str == "HIT"){base++;}
		else if(str == "OUT"){out_count++;}
		else if(str == "HOMERUN"){
		    sum[i] += base + 1;
		    base = 0;
		}
		
	}
	cout << sum[1] << endl;
	cout << sum[2] << endl;

	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        vector<int> point,runner;
        int d;
        string s;
        cin>>d;
        point.reserve(d);
        runner.reserve(d);
        for(int j = 0 ; j < d ; j++){
        fill(point.begin(),point.end(),0);
        fill(runner.begin(),runner.end(),0);
        for(int i=0; i < 3;){
                
                cin>>s;
                
                        if(s=="HIT"){
                        runner[j]++;
                                if(runner[j]>3){
                                        runner[j]--;
                                        point[j]++;
                                }
                        }
                        else if(s=="HOMERUN"){
                        point[j] += (1 + runner[j]);
                        runner[j] =0;
                        }
                        else if(s=="OUT"){
                        i++;
                        }
                
                }
        
        }
        
        for(int i = 0;i < d; i++) cout<<point[i]<<endl; 
}

C++: #include <iostream>
using namespace std;
int main(){
  int n,rui[3],outcnt,i,j,k,point,homeruncnt;
  string data;
  cin >> n;
  for(i=0;i<n;i++){
    outcnt=0;
    homeruncnt=0;
    point=0;
    for(j=0;j<3;j++)
      rui[j]=0;
      while(1){
      cin >> data;
      if(data=="HIT"){
        if(rui[0]==0) rui[0]=1;
	else{
	  if(rui[1]==0) rui[1]=1;
          else{
	    if(rui[2]==0) rui[2]=1;
	    else point++;
	  }
	}
      }
      else if(data=="HOMERUN"){
        for(k=0;k<3;k++){
	  if(rui[k]==1){
	    homeruncnt++;
	    rui[k]=0;
	  }
	}
        point=point+homeruncnt+1;
	homeruncnt=0;
      }
      else{
        outcnt++;
      }
      if(outcnt==3){
	outcnt=0;
        cout << point << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int p, out;
int main(){
  int t;
  cin >> t;
  vector<int> v;
  string s;
  while(cin >> s){
    if(s == "HIT"){
      if(v.size()<3)v.push_back(0);
      else p++;
    }else if(s == "OUT"){
      out++;
      if(out == 3){
	cout << p << endl;
	p = out = 0;
	v.clear();
      }
    }else{
      p += v.size() + 1;
      v.clear();
    }
  }
  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;
	while(out==3){
	 cin>>E;
	 switch(E){
		case "HIT":
		if(T){point++;}
		T=S;S=F;F=true;
		break;
		case "HOMERUN":
		point++;
		if(F){point++;F=false;}
		if(S){point++;S=false;}
		if(T){point++;T=false;}
		break;
		case "OUT":
		out++;
		break;
	 }
	}
	cout<<point<<endl;
	//???????????§
	}
	
	return 0;
}

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

using namespace std;

int main(){
	int n , i = 1;
	int base = 0 , sum[100] = {} , out_count = 0;
	string str;

	cin >> n;
		
	while(1){
	    
		if(i > n) break;
		cin >> str;
		
		if(out_count >= 3){
			base = 0;
			i++;
		}
		if(base >= 4){
		    sum[i]++;
		    base = base - 1;
		}
		if(str == "HIT"){base++;}
		else if(str == "OUT"){out_count++;}
		else if(str == "HOMERUN"){
		    sum[i] += base + 1;
		    base = 0;
		}
		
	}
    for(int i = 0; i < n; i++){
        cout << sum[i + 1] << endl;
    }
    
	return 0;
}

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

using namespace std;

int main(void){
	int game;
	cin >> game;
	for(int i = 0; i < game; i++){
		int out = 0;
		int base = 0;
		int point = 0;
		string n;
		while(out < 3){
			cin >> n;
			if(n == "HIT"){
				base++;
				if(base == 4)
				point++;
			}else if(n == "OUT"){
				out++;
			}else if(n == "HOMERUN"){
				point += base + 1;
			}
		}
		cout << point << endl;
	}
	
	return 0;
}