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

int base[3];
int point = 0;
int out = 0;
int n;

//イニング終わり
void reset_base() {
	for (int i = 0; i < 3; ++i) {
		base[i] = 0;
	}
}

//シングルヒット
void Single_hit() {
	point += base[2];
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
}

//ホームラン
void HomeRun() {
	for (int i = 0; i < 2; ++i) {
		point += base[i];
		base[i] = 0;
	}
	++point;
}

void Out() {
	++out;
	if (out == 3) {
		reset_base();
		out = 0;
		cout << point << endl;
		point = 0;
		--n;
	}
}


int main() {
	cin >> n;
	string s;
	while (n) {
		cin >> s;
		if (s == "HIT") {
			Single_hit();
		}
		else if (s == "HOMERUN") {
			HomeRun();
		}
		else if (s == "OUT") {
			Out();
		}
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int base[3] = { 0, 0, 0 };
int out = 0;
int score = 0;
int n;
string event[100];
int eventnum = 0;
int a = 0;

void Hit()
{
	if (base[2] == 1)
	{
		base[2] = 0;
	}
	if (base[1] == 1)
	{
		base[2] = 1;
	}
	if (base[0] == 1)
	{
		base[1] = 1;
	}
	else if (base[0] == 0)
	{
		base[0] = 1;
	}
}

void Homerun()
{
	for (int j = 0; j < 3; j++)
	{
		base[j] = 0;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < 3 * n; i++)
	{
		while (true)
		{
			cin >> event[a];
			if (event[a] == "OUT")
			{
				a += 1;
				eventnum += 1;
				break;
			}
			else
			{
				a += 1;
				eventnum += 1;
			}

		}
	}

	for (int i = 0; i < eventnum; i++)
	{
		if (event[i] == "HIT")
		{
			if (base[2] == 1)
			{
				score += 1;
			}
			Hit();
		}
		else if (event[i] == "HOMERUN")
		{
			score += base[0] + base[1] + base[2] + 1;
			Homerun();
		}
		else
		{
			out += 1;
			if (out == 3)
			{
				cout << score << endl;
				for (int j = 0; j < 3; j++)
				{
					base[j] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;

void Calc();

int main(){
    int n;
    cin >> n;
    
    for(int i=0; i<n; i++){
        Calc();
    }
    
    return 0;
}

void Calc(){
    int score = 0;
    int outCount = 0;
    string event;
    int runners[3]={};
    
    while(1){
        cin >> event;
        
        if(event == "HIT"){
            if(runners[2] == 1){
                score++;
            }
            
            for(int i=2; i>0; i--){
                runners[i] = runners[i-1];
            }
            runners[0] = 1;
        }
        
        else if(event == "HOMERUN"){
            score++;
            for(int i=0; i<3; i++){
                score += runners[i];
                runners[i] = 0;
            }

        }
        
        else{
            outCount++;
        }
        
        if(outCount == 3){
            cout << score << "\n";
            break;
        }
        
    }
    return;
}

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

int main()
{
	int n,inning=0;
	int inningp[40] = {0};
	string ivent;

	cin >> n ;
	while (1)
	{
		int r=0, p=0, o=3;                        //r = ???????????????p = ?????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p++;
				}
			}

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)                       //?????? = ???????????? + ????????????(1???)
				{
					p += 4;
				}
				else
				{
					p += r + 1;
				}
				r = 0;                            //??????????????????????????????
			}
			else if (ivent=="OUT")
			{
				o--;
			}
		}

		inningp[inning] = p;                      
		inning++;
		if (n == inning) break;

	}

	for (int i = 0; i < n; i++)
	{
		cout << inningp[i] << endl;
	}

	return 0;
}

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

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

using namespace std;

int main() {
	int n;
	int base = 0, out = 0, score = 0;
	cin >> n;  
    while(1) {
        char str[10];
        if(EOF == scanf("%s", str)) break;
        if(!strcmp(str, "OUT")) {
            out++;
            if(out >= 3) {
                cout << score <<endl;
                score = out = base = 0;
                n--;
            }
        } else if(!strcmp(str, "HOMERUN")) {
            score += base + 1;
            base = 0;
        } else {
            base++;
            if(base >= 4) {
                score++;
                base--;
            }
        }
    }
    if(n) {
        cout << score << endl;
    }
	return 0;
}

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

int main() {
    int N;
    cin >> N;

    string event;

    for (int n = 0; n != N; ++n) {
        
        int runners = 0, points = 0, out = 0;
        
        while (out < 3) {
            cin >> event;
            if (event == "OUT") out++;
            if (event == "HIT") {
                if (runners == 3) {
                    points++;
                }    
                else {
                    runners++;
                }
            }
            if (event == "HOMERUN") {
                points += runners + 1;
                runners = 0;
            }
        }
        cout << points << endl;
    }
}

C++: #include<stdio.h>
#include<string.h>
main(){
    char a[10];
    int n,i,out=0,base=0,score=0;
    scanf("%d",&n);
    while(n!=0){
        scanf("%s",a);
        if(!strcmp(a,"HIT")){
            base++;
            if(base>3){
                base--;
                score++;
            }
        }
        if(!strcmp(a,"OUT")){
        out++;
        }
        if(!strcmp(a,"HOMERUN")){
            score+=base+1;
            base=0;
        }
        if(out==3){
            n--;
            out=0;
            printf("%d\n",score);
            score=0;
            base=0;
        }
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  int out=0,b=0,p= 0;
  while(cin >> s){
    if(s == "OUT" && out == 2){
      out = 0;
      b = 0;
      n--;
      cout << p << endl;
      p = 0;
      if(n == 0)  break;
    } 
    if(s == "OUT") out++;
    if(s == "HIT"){
      if(b == 3 ) p++;
      else b++;
    }
    if(s == "HOMERUN"){
      p += b + 1;
      b = 0;
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  while(n--){
    int out=0, base = 0, score = 0;

    while(out<3){
      string s;
      cin >> s;
      if(s == "OUT"){
	out++;
      }else if(s == "HIT"){
	base++;
	if(base == 4){
	  base--;
	  score++;
	}
      }else{
	score += base + 1;
	base = 0;
      }
    }

    cout << score << endl;
  }
}

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

using namespace std;

int main() {
    int n, runner, out, score;
    string s;

    cin >> n;

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

        while (out < 3) {
            cin >> s;

            if(s == "HIT") {
                runner++;
                if(runner > 3) {
                    score++;
                    runner = 3;
                }
            } else if(s == "HOMERUN") {
                score += runner+1;
                runner = 0;
            } else {
                out++;
            }
        }
        cout << score << endl;
    }

    return 0;
}