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>

class Baseball{

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

public:

	Baseball(){
		point = 0;
		out = 0;
		base = 0;
	}

	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();

		while(baseball.get_out() != 3){
			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();

		}

		std::cout >> baseball.get_point() >> std::endl;
	}

	return 0;
{

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

int main(){
  int n;
  int base[3];
  int out, score;
  
  string event;
  std::cin >> n;
  for(int i=0; i<n; i++){
    base[0] = 0;
    base[1] = 0;
    base[2] = 0;
    out = 0;
    score = 0;
    while(out!=3){
      std::cin >> event;
      if(event=="HIT"){
        if(base[2]>=1){
          base[2]--;
          score++;
        }
        if(base[1]>=1){
          base[1]--;
          base[2]++;
        }
        if(base[0]>=1){
          base[0]--;
          base[1]++;
        }
        base[0]++;
      }else if(event=="HOMERUN"){
        score += base[2];
        base[2] = 0;
        score += base[1];
        base[1] = 0;
        score += base[0];
        base[0] = 0;
      }else{
        out++; 
      }
    }
    std::cout << score << std::endl;
  }
  
  return 0;
}

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


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

    string temp; getline(cin, temp);

    for (int n = 0; n != N; ++n) {
        int bases[3] = {0};
        string event;
        int runs = 0, outs = 0;
        
        while (cin >> event) {
            if (event == "HIT") {
                if (bases[2] == 1) {
                    runs++;
                    bases[2] == 0;
                }
                if (bases[1] == 1) {
                    bases[1] = 0;
                    bases[2] = 1;
                }
                if (bases[0] == 1) {
                    bases[0] = 0;
                    bases[1] = 1;
                }
                bases[0] = 1;
            }
            if (event == "HOMERUN") {
                for (int i = 0; i != 3; ++i) {
                    if (bases[i] == 1) {
                        runs++;
                        bases[i] = 0;
                    }
                }
                runs++;
            }
            if (event == "OUT") {
                outs++;
                if (outs == 3) {
                    break;
                }
            }
        }
        cout << runs << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	cin >> n;
	while(n--){	
		string s;
		int ans = 0 , cur = 0 , out = 0;
		while(out != 3 && cin >> s){
			if(s=="HIT"){
				cur = (cur << 1)+1;
				if(cur&8)cur -= 8 , ans++;
			}else if(s=="HOMERUN"){	
				ans += !!(cur&1) + !!(cur&2) + !!(cur&4) + 1;
				cur = 0;
			}else if(s=="OUT"){
				out++;
			}
		}
		cout << ans << endl;
		
	}
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n,i=0,out=0,g=0;
	int cange=0,score[2]={0,0};
	char evn[100][7];
	int base[4]={0,0,0,0};
	cin >> n;
	while(n!=g){
		cin >> evn[i];
		if(evn[i][1]=='I'){
			base[3]+=base[2];
			base[2]=base[1];
			base[1]=base[0];
			base[0]=1;
		}
		if(evn[i][1]=='O'){
			base[3]+=base[2]+base[1]+base[0]+1;
			base[2]=0;base[1]=0;base[0]=0;
		}
		if(evn[i][0]=='O'){
			out++;
		}
		if(out==3){
			out=0;
			base[0]=0;
			base[1]=0;
			base[2]=0;
			if(cange==0){
			score[0]=base[3];
			base[3]=0;
			cange=1;
			g++;
			}
			else{
				score[1]=base[3];
				score[3]=0;
				cange=0;
				g++;
			}
		}
	}
	cout << score[0] << endl <<score[1];
return 0;
}

C++: #include <cstdio>
#include <cstring>

int singlehit(char *base, int score);
int homerun(char *base, int score);

int main(void)
{
    int number;
    scanf("%d", &number);
    
    char event[10];
    int out_num;
    char base[4];
    while (number != 0){
        int score = 0;
        for (int i = 0; i < 4; i++){
            base[i] = '0';
        }
        for (out_num = 0; out_num != 3;){
            scanf("%s", event);
            if (strcmp(event, "HIT") == 0){
                score = singlehit(base, score);
            }
            else if (strcmp(event, "HOMERUN") == 0){
                score = homerun(base, score);
            }
            else {
                out_num++;
            }
        }
        printf("%d\n", score);
        number--;
    }
    
    return (0);
}

int singlehit(char *base, int score)
{
    base[1]++;
    if (base[1] == '2'){
        base[2]++;
        base[1]--;
    }
    if (base[2] == '2'){
        base[3]++;
        base[2]--;
    }
    if (base[3] == '2'){
        score++;
        base[3]--;
    }
    
    return (score);
}

int homerun(char base[], int score)
{
    for (int i = 0; i < 4; i++){
        if (base[i] == '1'){
            score++;
            base[i] = '0';
        }
    }
    score++;
    return (score);
}

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

const string hr = "HOMERUN";
const string h = "HIT";
const string o = "OUT";

int main() {
	int n;
	cin >> n;
	array<int,100>point;
	for (int j = 0; j < n; j++){
		string s;
		int bs = 0, p = 0;
		for (int i = 0; i < 3;){
			cin >> s;
			if (s == o){
				i++;
			}
			else if (s == h){
				if (bs == 3)
					p += 1;
				else bs += 1;
			}
			else if (s == hr){
				p += bs + 1;
				bs = 0;
			}
		}
		point[j] = p;
	}
	for (int i = 0; i != point.size(); i++){
		cout << point[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	while(n--){
		int runner = 0, out = 0, score = 0;
		while(out < 3){
			string e;
			cin >> e;
			if(e == "HIT"){
				runner = (runner << 1) + 1;
				if(runner & 0xf8){ ++score; }
			}else if(e == "HOMERUN"){
				++score;
				if(runner & 0x01){ ++score; }
				if(runner & 0x02){ ++score; }
				if(runner & 0x04){ ++score; }
				runner = 0;
			}else if(e == "OUT"){
				++out;
			}
			runner &= 0x07;
		}
		cout << score << endl;
	}
	return 0;
}

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++;
				printf("a");
			}
			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;
}