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>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<char, int>P;

int main(){
	int n; cin >> n;
	rep(i, n) {
		int a[3]{};
		int cnt = 0, out = 0;
		while (1) {
			string s; cin >> s;
			if (s == "HIT") {
				if (a[2]) { a[2] = 0; cnt++; }
				for (int i = 2; i >= 1; i--)if (a[i - 1]) { a[i] = 1; a[i - 1] = 0; }
				a[0] = 1;
			}
			if (s == "HOMERUN") { cnt++; rep(i, 3)if (a[i]) { a[i] = 0; cnt++; } }
			if (s == "OUT") { if (out == 2) { cout << cnt << endl; break; } out++; }
		}
	}
	return 0;
}

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

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

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT"){
				baseball.add_out();
			
				if(baseball.get_out() == 3)
					break;
				
			}
		}
	std::cout << baseball.get_point() << std::endl;
	}

	return 0;
}

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

int main(){
    int n;
    cin>>n;
    while(n--){
        string s;
        int out=0,score=0,base=0;
        while(out<3){
            cin>>s;
            if(s=="HIT"){
                base++;
                if(base>3){
                    score+=base%3;
                    base-=base%3;
                }
            }
            if(s=="HOMERUN"){
                score+=base+1;
                base=0;
            }
            if(s=="OUT"){
                out++;
            }
        }
        cout<<score<<endl;;
        
    }
}

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

class Baseball{
private:
	int first;
	int second;
	int third;
	int score;
	int count;
public:
	Baseball(){
		first=0;
		second=0;
		third=0;
		score=0;
		count=0;
	}
	int getScore(){
		return score;
	}
	void hit(){
		score+=third;
		third=second;
		second=first;
		first=1;
	}
	void homerun(){
		score+=third+second+first+1;
		first=0;
		second=0;
		third=0;
	}
	void out(){
		count++;
	}
	int getCount(){
		return count;
	}
}

int main(){
	int inning;
	std::cin >> inning;

	for(int i=0;i<inning;i++){
		Baseball attack;
		std::string result;
		while(attack.getCount()<3){
			std::cin >> result;

			if(result == "HIT"){
				attack.hit();
			} else if(result == "HOMERUN"){
				attack.homerun();
			} else if(result == "OUT"){
				attack.out();
			}
		}
		std::cout << attack.getScore() <<std::endl;
	}

    return 0;
}

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

int main(){
	int n, score=0, out=0;
	int rui[4];
	string s;

	for(int i=0 ; i<4 ; i++){
		rui[i] = (i==0)? 1 : 0 ;
	}
	cin >> n ;
	
	while( n > 0 ){
		
		cin >> s;
		if( s == "HIT" ){
			if( rui[1] == 1 ){
				if( rui[2] == 1 ){
					( rui[3] == 1 )? score++ : rui[3] = 1 ;
				}else{
					rui[2] = 1;
				}
			}else{
				rui[1] = 1;
			}
		}else if( s == "OUT" ){
			out++;
		}else if( s == "HOMERUN" ){
			for(int i=0 ; i<4 ; i++){
				score += rui[i];
				if(i>=1) rui[i] = 0;
			}
		}
			
		if(out==3){
			out = 0;
			n--;
			for(int i=0 ; i<4 ; i++){
				rui[i] = (i==0)? 1 : 0 ;
			}
			cout << score << endl;
			score = 0;
		}
	}
	return 0;
}

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

class Base {
public:
	Base() {
		score = 0;
		outNum = 0;
		first = false;
		second = false;
		third = false;
	}
	void hit() {
		if (third) {
			score++;
		}
		third = second;
		second = first;
		first = true;
	}
	void homerun() {
		if (first) {
			first = false;
			score++;
		}
		if (second) {
			second = false;
			score++;
		}
		if (third) {
			third = false;
			score++;
		}
		score++;
	}
	void out() {
		outNum++;
		if (outNum > 2) {
			cout << score << endl;
			score = 0;
			outNum = 0;
			first = false;
			second = false;
			third = false;
		}
	}
	
private:
	int score;
	int outNum;
	bool first;
	bool second;
	bool third;
};


int main() {
	Base base;
	string str;
	int inning;
	int count = 0;

	cin >> inning;

	while (count < inning * 3) {
		char data[10];
		cin >> str;
		if (str == "HIT") {
			base.hit();
		}else if (str == "HOMERUN") {
			base.homerun();
		}
		else if(str == "OUT"){
			base.out();
			count++;
		}
	}
	return 0;
}

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


class Baseball{
	int out;
	std::string runner;
	int score;
public:
	Baseball(){
		out = 0;
		runner.clear();
		score = 0;
	}
	
	int get_score(){ return score;}
	void event_out(){ ++out;}
	void event_hit();
	void event_homerun();
	void play_game();
};


void Baseball::event_hit(){
	int place;
	if((place = runner.find("3", 0)) != -1){
		runner.erase(place);
		++score;
	}
	
	if((place = runner.find("2", 0)) != -1){
		runner.replace(place, 1, "3");
	}
	
	if((place = runner.find("1", 0)) != -1){
		runner.replace(place, 1, "2");
	}
	
	runner.insert(0, "1");
}

void Baseball::event_homerun(){
	score += runner.size() + 1;
	runner.clear();
}

void Baseball::play_game(){
	std::string event;
	while(std::cin >> event){
		if(event == "HIT"){
			event_hit();
		}
		else if(event == "HOMERUN"){
			event_homerun();
		}
		else if(event == "OUT"){
			event_out();
			if(out == 3){
				break;
			}
		}
	}
}

int main(){
	int game_num;
	std::cin >> game_num;
	for(int i = 0; i < game_num; ++i){
		Baseball baseball;
		baseball.play_game();
		std::cout << baseball.get_score() << std::endl;
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int state;

int hit(int times) {
	int ret = 0;
	for (int i = 0; i < times; ++i) {
		ret += state & 1;
		state >>= 1;
	}
	return ret;
}

int main() {
	int n; cin >> n;
	for (int k = 0; k < n; ++k) {
		int out = 0, point = 0;
		state = 0;
		while (out < 3) {
			string str; cin >> str;
			if (str == "HIT") point += hit(1), state |= 4;
			else if (str == "HOMERUN") point += hit(3) + 1;
			else if (str == "OUT") ++out;
		}
		cout << point << endl;
	}
}

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

int main(void)
{
	int n;
	string _event;

	cin >> n;
	for(int i=0; i<n; i++)
	{
		int outN=0;
		int score=0;
		int runnerState=0;

		while(1)
		{
			cin >> _event;
			if(_event == "HIT")
			{
				runnerState <<= 1;
				runnerState |=  1;

				if(runnerState & 0x08)
				{
					runnerState &= ~(0x08);
					score ++;
				}
			}

			if(_event == "HOMERUN")
			{
				score++;
				while(runnerState != 0)
				{
					runnerState >>= 1;
					score++;
				}
			}

			if(_event == "OUT")
			{
				outN++;
				if(outN == 3)break;
			}
		}
		cout << score << endl;
	}
	return 0;
}