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 <vector>
#include <cmath>

auto main()
 -> int{

	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);

	int n, out = 0, base = 0, point = 0;
	std::string cmd;

	std::cin>> n;
	for(int i=0;i < n;i++ ){
		out = 0;
		base = 0;
		point = 0;
		while(out < 3){
			std::cin>> cmd;
			if(cmd == "HIT"){
				base <<= 1;
				base += 1;
				if(base > 8){
					base -= 8;
					point++;
				}
			}else if(cmd == "OUT"){
				out++;
			}else{
				for(int i = 2;i >= 0 ;i--){
					if(base - pow(2,i) >= 0){
						base -= pow(2,i);
						point++;
					}
				}
				point++;
			}
		}
		std::cout<< point <<"\n";
	}

	return 0;
}

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

using namespace std;

int main(){
        string t;
        int i,r,score,o,ini;
        score = 0;
        cin >> ini;
        for(i=0;i<ini;i++){
        while(1){
        cin >> t;
        if(t == "HIT"){
                r++;
                if(r == 4){
                        score++;
                        r--;
                }
        }else if(t == "OUT"){
                o++;
                if(o == 3){
                        r = o = 0;
                        break;
                }
        }else if(t == "HOMERUN"){
                score += r + 1;
                r = 0;
        }
        }
        cout << score << endl;
        score = 0;
        }
return 0;
}

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

void hit(int &score,int &base){
    base <<= 1;
    score += 1 & base>>3;
    base |= 1;
}

void homerun(int &score,int &base){
    for(int i=0;i<3;i++){
        score += base>>i & 1;
        base &= ~(1<<i);
    }
    score++;
}

int main(){
    int score,base,out_c,n;
    string s;

    cin>>n;
    cin.ignore();

    while(n--){
        score=0;
        base=0;
        out_c=0;
        while(out_c<3){
            getline(cin,s);
            if(s=="HIT"){
                hit(score,base);
            }else if(s=="HOMERUN"){
                homerun(score,base);
            }else{
                out_c++;
            }
        }

        cout<<score<<endl;
    }

    return 0;
}

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

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

	for (int re = 0;re < a;re++) {
		int ou = 0;
		int r = 0;
		int ap = 0;

		while (ou != 3) {
			string s;
			cin >> s;

			if (s == "OUT")ou++;

			else if (s == "HIT") {
				r++;
				if (r == 4) {
					ap++;
					r--;
				}
			}

			else if (s == "HOMERUN") {
				ap += r;
				r = 0;
				ap++;
			}
		}
		cout << ap << endl;
	}
	return 0;
}

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

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

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


class Baseball {
public:
    int score;                //得点
    int count;                //アウトカウント
    std::queue<int> runner;   //ランナー

    //コンストラクタ
    Baseball(int sc,int co){
        score = sc;
        count = co;
        while(!runner.empty()){
            runner.pop();
        }
    }
    
    //ヒット
    void hit(){
        if(runner.size() == 3){
            ++score;
        }
        runner.push(1);
    }
    
    //ホームラン
    void homerun(){
        while(!runner.empty()){
            ++score;
            runner.pop();
        }
        ++score;;
    }
    
    //アウト
    void out(){
        ++count;
    }
};


int main(){
    int n;
    std::string event;
    
    std::cin >> n;
    
    Baseball game(0,0);
    
    while(n > 0 && std::cin >> event){
        if(event =="HIT")
            game.hit();
        else if(event == "HOMERUN")
            game.homerun();
        else
            game.out();
        
        if(game.count == 3){
            --n;
            std::cout << game.score << std::endl;
            game = Baseball(0,0);
        }
    }
}

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

int Baseball()
{
    int num_of_runner = 0, num_of_out = 0, point = 0;
    std::string event;
    while(num_of_out != 3){
        std::cin >> event;
        if(event == "HIT"){
            if(num_of_runner == 3)
                ++point;
            else
                ++num_of_runner;
        }
        else if(event == "HOMERUN"){
            point += 1 + num_of_runner;
            num_of_runner = 0;
        }
        else
            ++num_of_out;
    }
    
    return point;
}

int main()
{
    u_int num_of_inning;
    std::cin >> num_of_inning;
    
    for(u_int i = 0; i < num_of_inning; ++i){
        std::cout << Baseball() << std::endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void)
{
	int score = 0;
	int runner = 0;
	int out = 0;
	int inning = 1;
	int inning_limit;
	cin>>inning_limit;
	int inning_score[34] = {};
	int insc = 0;
	bool rui_1 = false;
	bool rui_2 = false;
	bool rui_3 = false;
	string hit[100];
	int i = 0;
	while(cin>>hit[i]){
		i++;
	}
	for(int j = 0;j<i;j++){
		if(hit[j] == "HIT"){
			if(rui_3==true){
				insc++;
				rui_3=false;
			}else{
				runner--;
			}
			rui_3 = rui_2;
			rui_2 = rui_1;
			rui_1 = true;
			runner++;
		}else if(hit[j] == "HOMERUN"){
			insc += runner + 1;
			runner = 0;
		}else if(hit[j] == "OUT"){
			out++;
			if(out== 3){
				inning++;
				runner = 0;
				out = 0;
				inning_score[inning] = insc;

				score += insc;
				if(inning > inning_limit){
					break;
				}
			}
		}
	}

	for(int i = 1; i < inning_limit;i++){
		cout<<inning_score[i]<<endl;
	}

	return 0;
}