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*****/
#include <iostream>
#include <fstream>
#include <string>
/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	string order;
	int baseman[4];
	int point;
	int out_count;
	/*****処理部*****/
	int n;
	cin >> n;
	for(int loop = 0;loop<n;loop++){
		point = 0;
		out_count=0;
		for(int i=0;i<4;i++){
			baseman[i] = 0;
		}
		while(out_count != 3){
			baseman[0] = 1;
			cin >> order;
			if(order == "HIT"){
				if(baseman[3] == 1)	point++;
				for(int i=3;i>0;i--){
					baseman[i] = baseman[i-1];
				}
			}else if(order == "OUT"){
				out_count++;
			}else if(order == "HOMERUN"){
				for(int i=0;i<4;i++){
					if(baseman[i] == 1)	point++;
					baseman[i] = 0;
				}
			}
		}
		cout << point << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

int main(){
	string str;
	int n;
	getline( cin, str );
	sscanf( str.c_str(), "%d", &n );

	for( int i=0; i<n; i++ ){
		int out = 0;
		int score = 0;
		bool first=false, second=false, third=false;

		while( out < 3 ){
			getline( cin, str );
			if( str == "HIT" ){
				if(third){ score++; third=false; }
				if(second){ third=true; second=false; }
				if(first){ second=true; first=false; }
				first = true;
			}
			else if( str == "HOMERUN" ){
				if(third){ score++; third=false; }
				if(second){ score++; second=false; }
				if(first){ score++; first=false; }
				score++;
			}
			else if( str == "OUT" ){
				out++;
			}
		}
		cout << score << endl;
	}
}

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

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

    string temp; getline(cin, temp);

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

C++: //0103
#include<string.h>
#include<stdio.h>
int main()
{
	int n,op,rn[3]={0},r;
	char s[8];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		r=0;
		op=0;
		while(1){
			if(strcmp("OUT",s)==0){
				op++;
			}else if(strcmp("HIT",s)){
				if(rn[2]){
					rn[2]=0;
					r++;
				}
				if(rn[1]){
					rn[1]=0;
					rn[2]=1;
				}
				if(rn[0]){
					rn[1]=1;
				}
				rn[0]=1;
			}else{
				for(int j=0;j<3;j++){
					if(rn[j]==1){
						rn[j]=0;
						r++;
					}
					r++;
				}
			}
			if(op>=3){
				break;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int main(){
    int hit, out, score, data_set_num;
    std::string event;
    std::getline(std::cin,str);
    sscanf(str.c_str(),"%d ",&data_set_num);

    while(data_set_num--){
        std::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;
            score = 0;
        }
    }

    return 0;
}

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

using namespace std;

int main() {

	int N;
	cin >> N;

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

		int out = 0, point = 0, a[4] = {};
		string event;

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

			if (event == "HIT") {
				a[3] = a[2];
				a[2] = a[1];
				a[1] = a[0];
				a[0] = 1;
				if (a[3] == 1) {
					point++;
					a[3] = 0;
				}
			}
			if (event == "HOMERUN") {
				for (int j = 0; j < 3; j++) {
					if (a[j] == 1) {
						point++;
					}
					a[j] = 0;
				}
				point++;
			}
			if (event == "OUT") {
				out++;
			}
		}
		cout << point << endl;
	}

	return 0;
}

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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int base = 0, out = 0, point = 0;
		while (out != 3) {
			string s;
			cin >> s;
			if (s == "HIT") {
				if (base == 3) {
					point++;
				}
				else if (base < 3) {
					base++;
				}
			}
			else if (s == "HOMERUN") {
				point += base + 1;
				base = 0;
			}
			else {
				out++;
			}
		}
		cout << point << endl;
	}
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<string> a(101);
    bool run[30]={false, false, false};
    int out=0, e=0;
    int point[500] = {};
    int j=0;
    int k=0;
    while(cin >> a[j]) {
        if(a[j]=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a[j]=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        j++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }
 
}

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

using namespace std;

int main(){
	int n , i = 1;
	int base = 0 , sum[3] = {} , out_count = 0;
	string str;

	cin >> n;
		
	while(1){
	    
		if(i > n) break;
		cin >> str;
		
		if(out_count >= 3){
			base = 0;
			i++;
		}
		if(base >= 4){
		    sum[i]++;
		    base = base - 1;
		}
		if(str == "HIT"){base++;}
		else if(str == "OUT"){out_count++;}
		else if(str == "HOMERUN"){
		    sum[i] += base + 1;
		    base = 0;
		}
		
	}
	cout << sum[1] << endl;
	cout << sum[2] << endl;

	return 0;
}