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<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;
 
int main(void){
  int out = 0, base = 0,point = 0;
  int n;
  cin>>n;
  int i=0;
  while(true){
    i++;if(i>20)break;
    string s;
    cin>>s;
    //cout<<s<<endl;
     
    if(s=="OUT"){
      out++;
      //cout<<out<<endl;
      if(out==3){
    //cout<<"poin"<<endl<<endl;;
    cout<<point<<endl;
    point=0;
    out = 0;
    base = 0;
    n--;
    if(n==0)break;
      }
    }
    else if(s=="HIT"){
      base++;
      //cout<<base<<endl;
      if(base>=4){
    //cout<<base<<" "<<point<<endl;
    point++;
    base--;
    //cout<<base<<" "<<point<<endl;
      }
    }
     
    if(s=="HOMERUN"){
      point += base+1;
      base = 0;
              
    }
     
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[4]={0},k=0,l=0;
  string s;
  cin>>n;
  while(k!=n){
    cin>>s;
    if(s=="HIT"){
      if(!a[0])a[0]++;
      else {
        if(!a[1])a[1]++;
        else{
          if(!a[2])a[2]++;
          else a[3]++;
        }
      }
    }
    else if(s=="OUT"){
      l++;
      if(l==3){
        a[1]=a[2]=a[0]=l=0;
        k++;
      }
    }
    else{
    a[3]+=1+a[1]+a[2]+a[0];
    a[1]=a[2]=a[0]=0;
    }
  }
  cout<<a[3]<<endl;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

using namespace std;

int base=0;
int score = 0;
int out=0;

void addRunner(){
	switch (base){
	case 0:base = 1; break;
	case 1:base = 11; break;
	case 10:base = 101; break;
	case 11:base = 111; break;
	case 100:base = 1; score++; break;
	case 101:base = 11; score++; break;
	case 111:base = 111; score++; break;
	default:printf("any error"); break;
	}
}

int main(){
	int cining=0,ining;
	char eventName[9];

	cin >> ining;

	while(1){
		cin >> eventName;
		if (strcmp("HIT", eventName) == 0){
			addRunner();
		}
		else if (strcmp("OUT",eventName) == 0){
			out++;
			if (out == 3){
				printf("%d\n", score);
				score = out = base = 0;
				cining++;
				if (cining == ining)break;
			}
		}
		else if (strcmp("HOMERUN", eventName) == 0){
			switch (base){
			case 0:score++; break;
			case 1:score += 2; break;
			case 10:score += 2; break;
			case 11:score += 3; break;
			case 100:score += 2; break;
			case 101:score += 3; break;
			case 110:score += 3; break;
			case 111:score += 4; break;
			default:printf("any error"); break;
			}
			base = 0;
		}
	}

	return 0;
}

C++: #include <string>
#include <iostream>
using namespace std;
int N, c1, c2, c3, out, ret; string S;
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		c1 = 0, c2 = 0, c3 = 0, out = 0, ret = 0;
		while (out != 3) {
			cin >> S;
			if (S == "HIT") {
				ret += c3, c3 = c2, c2 = c1, c1 = 1;
			}
			else if (S == "HOMERUN") {
				ret += c1 + c2 + c3 + 1, c1 = 0, c2 = 0, c3 = 0;
			}
			else {
				out++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: int main(){
  int n;
  string input;
  int out;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    first = second = third = out = point = 0;
    out = 0;
    while(out < 3)
    {
      cin >> input;
      if(input == "OUT")
      {
        out++;
        continue;
      }
      else if(input == "HIT")
      {
        point += third;
        third = second;
        second = first;
        first = 1;
        continue;
      }
      else if(input == "HOMERUN")
      {
        point += first + second + third + 1;
        first = second = third = 0;
        continue;
      }
    }
    cout << point << endl;
  }
  return 0;
}

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

int main(){
	
	string sim ;
	int n;
	int base=0 , point=0 , count=0 ;
	
	cin >> n ;
	
	for( int i=0 ; i<n ;){
		cin >> sim ;
		
		if( sim == "HIT" ){
			base++;
			if( base == 4 ){
				base=3;
				point++;
			}
		}
		else if( sim == "HOMERUN" ){
			point += base+1 ;
			base=0;
		}
		else if( sim == "OUT" ){
			count++;
			if( count%3 == 0 ){
				cout << point << endl ;
				i++;
				base=0;
				point=0;
			}
		}
	}
	
return 0;
}

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

int main(){
	int n , score , runner , outcount;
	cin >> n;
	for(int i=0 ; i<n ; i++){
		score=runner=outcount=0;
		string event;
		while(outcount<3){
			cin >> event;
			if (event=="HIT"){
				if(runner==3){
					score++;
				} else {
					runner++;
				}
			} else if (event=="HOMERUN"){
				score+=runner+1;
				runner=0;
			} else {
				outcount++;
			}
		}
		cout << score << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>

int singlehit(char *base, int score);
int homerun(char *base, int score);

int main(void)
{
    int number;
    scanf("%d", &number);
    
    char event[10];
    int out_num;
    char base[4];
    while (number != -1){
        int score = 0;
        for (int i = 0; i < 4; i++){
            base[i] = '0';
        }
        for (out_num = 0; out_num != 3;){
            scanf("%s", event);
            if (strcmp(event, "HIT") == 0){
                score = singlehit(base, score);
            }
            else if (strcmp(event, "HOMERUN") == 0){
                score = homerun(base, score);
            }
            else {
                out_num++;
            }
        }
        printf("%d\n", score);
        number--;
    }
    
    return (0);
}

int singlehit(char *base, int score)
{
    base[1]++;
    if (base[1] == '2'){
        base[2]++;
        base[1]--;
    }
    if (base[2] == '2'){
        base[3]++;
        base[2]--;
    }
    if (base[3] == '2'){
        score++;
        base[3]--;
    }
    
    return (score);
}

int homerun(char base[], int score)
{
    for (int i = 0; i < 4; i++){
        if (base[i] == '1'){
            score++;
            base[i] = '0';
        }
    }
    score++;
    return (score);
}

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

using namespace std;

int main( void )
{
	long n;
	while(cin >> n) {
		string str;
		int outCount = 0, point = 0, base = 0;
		while(n) {
			cin >> str;
			switch(str[1]) {
				case 'I': // HIT
					++base;
					point += base/4;
					base = min(3, base);
					break;
				case 'U': // OUT
					if(++outCount == 3) {
						cout << point << endl;
						point = outCount = base = 0;
						--n;
					}
					break;
				case 'O': // HOMERUN
					point += base + 1;
					base = 0;
					break;
			}
		}
	}
	return 0;
}