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<stdio.h>

int main(void)
{
  char str[16]={};
  int n;
  int i;
  int score=0;
  int base=0;
  int out=0;

  scanf("%d", &n);

  for(i=0;i<n;i++)
    {
      scanf("%s", str);
      if(str[1]=='I')
        if(base==3)
          score++,base=0;
        else
          base++;
      else if(str[1]=='U')
        if(out==2)
          out=base=0;
        else
          out++;
      else if(str[1]=='O')
        score+=base+1,base=0;
    }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
 
int main(void)
{
    int base[3] = {0};
    char happend[50];
    int score, counts, n, i, j;
 
    scanf("%d\n", &n);
     
 
    for (i = 0; i < n; i++)
    {
        counts = 0;
        score = 0;
 
        while (counts != 3)
        {
            gets(happend);
 
            if (strcmp(happend, "HIT") == 0)
            {
                if (base[2] == 1)
                {
                    score++;
                    base[2] = 0;
                }
                if (base[1] == 1)
                {
                    base[2]++;
                    base[1] = 0;
                }
                if (base[0] == 1)
                {
                    base[1]++;
                    base[0] = 0;
                }
                base[0]++;
            }
            else if (strcmp(happend, "HOMERUN") == 0)
            {
                for (j = 0; j < 3; j++)
                    if (base[j] == 1)
                    {
                        base[j] = 0;
                        score++;
                    }
                score++;
            }
            else if (strcmp(happend, "OUT") == 0)
                counts++;
        }
 
        base[0] = 0;
        base[1] = 0;
        base[2] = 0;
 
        printf("%d\n", score);
    }
 
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(){
	int n,b[3]={0},p=0,o=0;
	char s[8];
	scanf("%d",&n);
	while(scanf("%s",s)!=EOF)
	{
		if(!strcmp(s,"HIT"))
		{
			if(b[2])p++,b[2]=0;
			if(b[1])b[2]=1,b[1]=0;
			if(b[0])b[1]=1,b[0]=0;
			b[0]=1;
		}
		if(!strcmp(s,"HOMERUN"))
			p+=b[2]+b[1]+b[0]+1,b[0]=b[1]=b[2]=0;
		if(!strcmp(s,"OUT"))
			o++;
		if(o==3)printf("%d\n",p),o=0,p=0,b[0]=b[1]=b[2]=0;
	}
	return 0;
}

C++: #include<cstdio>

int main(){
    int n;
    bool a,b,c;
    char event[20];
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        int score=0;
        a=b=c=false;
        int out =0;
        while(1){
            scanf("%s", event);
            if(event[1]=='I'){
                if(c)score++;
                c=b;
                b=a;
                a=true;
            }else if(event[1]=='O'){
                score++;
                if(a)score++;
                if(b)score++;
                if(c)score++;
                a=b=c=false;
            }else out++;
            if(out==3){
                printf("%d\n", score);
                break;
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	while(n--){
		int in[4]={0};
		string s;
		int co=0;
		while(cin>>s){
			if(s=="OUT")co++;
			if(co==3)break;
			if(s=="HIT"){
				rep(i,3){
					in[3-i]+=in[2-i];
					in[2-i]=0;
				}
				in[0]++;
			}
			if(s=="HOMERUN"){
				rep(i,3){
					in[3]+=in[i];
					in[i]=0;
				}
				in[3]++;
			}
			//cout<<in[0]<<" "<<in[1]<<" "<<in[2]<<" "<<in[3]<<endl;
		}
		cout<<in[3]<<endl;
	}
}

C++: #include<stdio.h>

int main(){
	char ev[30];
	int ten,n,out,rui[4];
	
	scanf("%d ",&n);
	
	while(n--){
		out=0;
		ten=0;
		rui[1]=rui[2]=rui[3]=0;
		while(out<3){
			scanf(" %s ",ev);
			
			if(ev[1]=='U'){
				++out;
			}
			if(ev[1]=='I'){
				if(rui[3]==1){
					++ten;
				}
				rui[3]=rui[2];
				rui[2]=rui[1];
				rui[1]=1;
			}
			if(ev[1]=='O'){
				ten+=rui[1]+rui[2]+rui[3]+1;
				rui[1]=rui[2]=rui[3]=0;
			}
//			printf("%d %d %d %d\n",ten ,rui[1],rui[2],rui[3]);
		}
		printf("%d\n",ten);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int n,OUT,SCORE;
bool F,S,T;
string str;
int main(){
  cin>>n;
  while(n--){
    OUT=SCORE=0;
    F=S=T=false;
    while(OUT<3){
      cin>>str;
      if(str=="OUT")OUT++;
      else if(str=="HIT"){
    if(T){SCORE++;T=false;}
    if(S){T=true;S=false;}
    if(F){S=true;}
    F=true;
      }else if(str=="HOMERUN"){
    if(T)SCORE++;
    if(S)SCORE++;
    if(F)SCORE++;
    SCORE++;
    T=S=F=false;
      }
    }
    cout<<SCORE<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int i, j, n, count, outcount, data[3];
  string event;

  cin >> n;

  for(i=0; i<n; ++i){
    count = 0;
    outcount = 0;
    for(j=0; j<3; ++j)
      data[j] = 0;

    while(1){
      cin >> event;

      if(event == "HOMERUN"){
        ++count;
        for(j=0; j<3; ++j){
          if(data[j] == 1){
            ++count;
            data[j] = 0;
          }
        }
      }else if(event == "HIT"){
        if(data[2] == 1) ++count;
        data[2] = data[1];
        data[1] = data[0];
        data[0] = 1;
      }else if(event == "OUT"){
        ++outcount;
      }

      if(outcount == 3) break;
    }

    cout << count << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	int n;
	string a[100][100];
	int p[100],co[100],run[100];
	cin >> n;

	for (int j = 0; j < n; j++)
	{
		p[j] = 0;
		co[j] = 0;
		run[j] = 0;
		for (int i = 0; i < 100; i++)
		{
			cin >> a[j][i];

			if (a[j][i] == "OUT")
			{
				p[j] += 1;
			}
			if (p[j] == 3)
			{
				break;
			}

			if (a[j][i] == "HIT")
			{
				run[j] += 1;
				if (run[j] == 4)
				{
					co[j] += 1;
					run[j] = run[j] - 1;
				}
			}
			else if (a[j][i] == "HOMERUN")
			{
				co[j] += run[j] + 1;
				run[j] = 0;
			}
		}

		cout << co[j] << endl;
	}
}

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

int main(){
    int hit, out, score, data_set_num;
    std::string event;
    cin >> data_set_num;


    while(data_set_num--){
        cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                hit = 3;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            core = 0;
        }
    }

    return 0;
}