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 <bits/stdc++.h>
using namespace std;
int point = 0;
int out = 0;
bool base[3];

//1... Single Hit  2... Home run  3...Out
void exec(int event) {
    switch(event) {
        case 1:
            if(base[2]){ base[2] = false; point++;}
            if(base[1]){ base[2] = true; base[1] = false;}
            if(base[0]){ base[1] = true; base[0] = false;}
            base[0] = true; break;
        case 2:
            point += base[0] + base[1] + base[2] + 1;
            memset(base, false, sizeof(base)); break;
        case 3:
            out++; break;
    }
}

int main(void) {
    int n; cin >> n;
    for(int r = 0; r < n; r++) {
        point = out = 0; memset(base, false, sizeof(base));
        while(out < 3) {
            string input; cin >> input;
            if(input == "HIT")          exec(1);
            else if(input == "HOMERUN") exec(2);
            else                        exec(3);
        }
        cout << point << endl;
    }
    return(0);
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  string odr;
  cin >> n;
  while(n--){
    int r = 0,sc = 0,out = 0;
    while(cin >> odr){
      if(odr == "HIT"){
	r++;
	if(r > 3){
	  r--;
	  sc++;
	}
	
      } else if( odr[0] == 'O'){

	out++;
	if(out > 2)break;

      }else {
	sc += r+1;
	r = 0;
      }
    }
    cout << sc << endl;
  }
}

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

int PrintPoint();

int main()
{
    int i;

    cin >> i;
    for(int c=0; c < i; c++)
        PrintPoint();

    return EXIT_SUCCESS;
}

int PrintPoint()
{
    int iPoint = 0;
    int iRunner = 0;
    string sEvent;
    for(int iOutCount = 0; iOutCount < 3;)
    {
        cin >> sEvent;
        if(sEvent == "HOMERUN")
        {
            iPoint += iRunner + 1;
            iRunner = 0;
        }
        if(sEvent == "HIT")
        {
            iRunner++;
            if(iRunner > 3)
            {
                iRunner -= 1;
                iPoint++;
            }
        }
        if(sEvent == "OUT")
            iOutCount++;
    }
    cout << iPoint << endl;
    return 0;
}

C++: main(){
	int c,y,t,o,p;
	char a[9];
	scanf("%d",&c);
	for(y=0;y<c;y++){
		for(t=o=p=0;;){
			if(!~scanf("%s",a))return 0;
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}c=1;
}

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

class Baseball{
	int point,out_count,runner;
public:
	Baseball(){
		point = 0;
		out_count = 0;
		runner = 0;
	}
	void game();
	void single_hit();
	void homerun();
	void out();
	int get_point(){ return point; }
	int get_out(){ return out_count; }
};

void Baseball::game(){
	std::string event;
	while(std::cin >> event){
		if(event == "HIT"){
			single_hit();
		}else if(event == "HOMERUN"){
			homerun();
		}else if(event == "OUT"){
			out();
		}
		if(get_out() == 3){
			break;
		}
	}
}

void Baseball::single_hit(){
	++runner;
	if(runner == 4){
		++point;
		--runner;
	}
}

void Baseball::homerun(){
	++runner;
	point += runner;
	runner = 0;
}

void Baseball::out(){
	++out_count;
}

int main(){
	int inning;
	std::cin >> inning;
	for(int i = 0; i < inning; ++i){
		Baseball baseball;
		baseball.game();
		std::cout << baseball.get_point() << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){
	int c,y,t,o,p;
	char a[9];
	for(y=0;y<c;y++){
		for(t=o=p=0;;){
			if(!~scanf("%s",a))return 0;
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	int n;
	cin>>n;
	while(n){
		int b[4]={0};
		int ten=0;
		int cint=0;
		while(cint!=3){
			cin>>a;
			if(a=="HIT"){
				for(int i=2;i>=0;i--){
						b[i+1]=b[i];
					}
					b[0]=1;
					if(b[3]==1){
						b[3]=0;
						ten++;
					}
			}
			if(a=="HOMERUN"){
				ten++;
				for(int i=0;i<3;i++){
					if(b[i]==1){
						ten++;
					}
					b[i]=0;
				}
			}
			if(a=="OUT"){
				cint++;
			}
		}
		cout<<ten<<endl;
		n--;
	}
}

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

int main(void){
     int atotal=0,btotal=0;
     int out=0;
     int n=0;
     bool one=false,two=false,three=false;
     string move="";
     cin >> n;
     for(int i=0;i<n;i++){
	  out = 0;
	  one=false;
	  two=false;
	  three=false;
	  do{
	       cin >> move;
	       if(move == "HIT"){
		    bool home;
		    home = three;
		    three = two;
		    two = one;
		    one = true;
		    if(home == true){
			 if(i%2 == 0){
			      atotal++;
			 }else{
			      btotal++;
			 }
		    }
		    // cout << "HIT" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;;
		    // cout << " " << endl;
	       }
	       if(move == "OUT"){
		    out++;
		    // cout << "OUT" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;
		    // cout << " " << endl;
	       }
	       if(move == "HOMERUN"){
		    if(i%2 == 0){
			 int t = 1;
			 if(one == true){
			      one = false;
			      t++;
			 }
			 if(two == true){
			      two = false;
			      t++;
			 }
			 if(three == true){
			      three = false;
			      t++;
			 }
			 atotal = atotal+t;
		    }else{
			  int t = 1;
			 if(one == true){
			      one = false;
			      t++;
			 }
			 if(two == true){
			      two = false;
			      t++;
			 }
			 if(three == true){
			      three = false;
			      t++;
			 }
			 btotal = btotal + t;
		    }
		    // cout << "z[" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;
		    // cout << " " << endl;
	       }
	  }while(out < 3);
     }
     cout << atotal << endl;
     cout << btotal << endl;
     return 0;
}

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

using namespace std;

int main()
{
	int n;
	int BS,OT,point;
	string s;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		BS = 0;
		OT = 0;
		point = 0;
		while(OT!=3)
		{
			cin >> s;
			if(s=="HIT")
			{
				BS++;
				if(BS>3)
				{
					point++;
					BS--;
				}
			}
			else if(s=="HOMERUN")
			{
				point+=(1+BS);
				BS=0;
			}
			else
			OT++;
		}
		printf("%d\n",point);
	}
}

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") runners++;
            if (runners == 4) {
                points++;
                runners--;
            }
            if (event == "HOMERUN") {
                points += runners + 1;
                runners = 0;
            }
        }
        cout << points << endl;
    }
}