Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

C++: #include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int n;
	cin>>n;
	REP(i, n) {
		int out = 0;
		int score = 0;
		vector<bool> rui(3, false);
		while(out < 3) {
			string hoge;
			cin>>hoge;
			if(hoge == "HIT") {
				if(rui[2]) {
					++score;
				}
				for(int j = 1; j >= 0; --j) {
					rui[j + 1] = rui[j];
				}
				rui[0] = true;
			} else if (hoge == "OUT") {
				++out;
			} else if(hoge == "HOMERUN") {
				score++;
				REP(j, 3) {
					if(rui[j]) ++score;
					rui[j] = false;
				}
			}
		}
		cout<<score<<endl;
	}
}

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

int main(){
	
	int n;
	string str;
	cin>>n;
	while(n>0){
		int base[4]={0};
		int o=0;
		while(o!=3){
		cin>>str;
		if(str=="HIT"){
			for(int i=3;i>0;i--){
				base[i]+=base[i-1];
				base[i-1]=0;
		}
			base[0]=1;
		}
			else if(str=="HOMERUN"){
				int k=1;
				for(int i=0;i<3;i++){
			if(base[i]==1)
				k++;
				base[i]=0;
				}
				base[3]+=k;
		}
			else if(str=="OUT")
				o++;
	}
		cout<<base[3]<<endl;
		n--;
	}
}

C++: #include<stdio.h>
int main(){
  int i,j,n;
  char c;
  int a=0;
  int score=0;
  int runner[3];
  int ining=0;
  int out=0;
  int event=1;
  char s[10];
  scanf("%d",&n);

  for(i=0; i < 3; i++) runner[i] = 0;
  for(;event<=n;){
    scanf("%s", s);

    if(s[1]=='I'/*HIT*/){ 
      if(runner[2]==1){
	score++;
	runner[2]--;
      }if(runner[1]==1){
	runner[2]++;
	runner[1]--;
      }
      if(runner[0]==1)
	{
	  runner[0]--;
	  runner[1]++;
	}
      runner[0]++;    
    }
    else if(s[1]=='O'/*HOMERUN*/){ 
      if(runner[2]==1){runner[2]--;score++;}	
      if(runner[1]){runner[1]--;score++;}
      if(runner[0]){runner[0]--;score++;}
      score++;
    }
    else if(s[1]=='U'/*OUT*/){
      out++;
      if(out==3){
	ining++;
	event++;
	out=0;
	runner[2]=0;runner[1]=0;runner[0]=0;
	printf("%d\n",score);
	score = 0;
      }
    }
  }
  return 0;
}

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 <iostream>
#include <string>
using namespace std;

int main( void )
{
	int cnt = 0;
	int n;
	cin >> n;
	for ( int i = 0; i < n && cnt < 100; i++ )
	{
		int point = 0;
		int runner = 0;
		int out = 0;
		while ( out < 3 && cnt < 100 )
		{
			cnt ++;
			string in;
			cin >> in;

			if ( in == "HIT" )
			{
				if ( runner == 3 )
					point ++;
				else
					runner++;
			}
			else if ( in == "HOMERUN" )
			{
				point += runner + 1;
				runner = 0;
			}
			else if ( in == "OUT" )
			{
				out ++;
			}
		}

		cout << point << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){

    int n, point, out;
    bool base[3];
    string ivent;

    cin >> n;

    for(int i = 0; i < n; ++i){

        point = 0;
        out = 0;
        memset(base, false, sizeof(base));

        while(out < 3){

            cin >> ivent;

            if(ivent == "HIT"){

                if(base[2]) point++;
                for(int j = 2; j >= 0; --j)
                    base[j] = base[j - 1];
                base[0] = true;

            }
            else if(ivent == "HOMERUN"){

                for(int j = 0; j < 3; ++j)
                    if(base[j]) ++point;
                ++point;
                memset(base, false, sizeof(base));

            }
            else if(ivent == "OUT"){

                ++out;

            }

        }

        cout << point << endl;

    }

}

C++: #include <iostream>
#include <string>
using namespace std;
main() {
	int n,p,r,a;
	string t;
	cin >> n;
	for(int i=0;i<n;i++){
		a=0;r=0;p=0;
		while(a<3){
			cin >> t;
			if(t=="HIT"){
				r++;
				if(r>3) {r--;p++;}
			} else if(t=="OUT"){
				a++;
			} else {
				p+=r+1;
				r=0;
			}
		}
		cout << p << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

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

int num,a,b,c;
int out,result;
int base[5] = {0};
char str0[132],str1[] = "OUT",str2[] = "HIT",str3[] = "HOMERUN";

int main()
{
    scanf("%d",&num);
    for(int i = 1; i <= num; i++)
    {
        while(1)
        {
            scanf("%s",str0);
            a = strcmp(str0,str1);
            b = strcmp(str0,str2);
            c = strcmp(str0,str3);
            if(a == 0)
            {
                out++;
                if(out == 3)break;
            }
            if(b == 0)
            {
                if(base[2] == 1)
                {
                    result++;
                    base[2] = 0;
                }
                if(base[1] == 1)
                {
                    base[1] = 0;
                    base[2] = 1;
                }
                if(base[0] == 1)
                {
                    base[1] = 1;
                    base[0] = 0;
                }
                if(base[0] == 0)
                {
                    base[0] = 1;
                }
                //printf("(%d,%d,%d)\n",base[0],base[1],base[2]);
            }
            if(c == 0)
            {
                result++;
                for(int j = 0; j < 3; j++)
                {
                    if(base[j] == 1)
                    {
                        result++;
                        base[j] = 0;
                    }

                }
            }
            //printf("[%d]\n",result);
        }
        printf("%d\n",result);
        out = 0;result = 0;
        for(int j = 0; j < 3; j++)
        {
            base[j] = 0;
        }
    }
}