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<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		char c[10];
		int sum=0,people=0,out=0;
		while(out<3){
			scanf("%s",c);
			if(c[1]=='I'){
				people++;
				if(people==4){
					sum+=1;
					people=3;}}
			if(c[1]=='O'){
				sum+=people+1;
				people=0;}
			if(c[1]=='U'){
				out++;}}
		printf("%d\n",sum);}
	return 0;}

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

int main(){

  int n;
  cin >> n;
  while(n){
    int out = 0,hit = 0,point= 0;
    while(out != 3){
      string s;
      cin >> s;
      if(s == "OUT") out++;
      else if(s == "HIT"){
	hit++;
	if(hit == 4){
	  point++;
	  hit = 3;
	}
      }
      else if(s == "HOMERUN"){
	point += hit + 1;
	hit = 0;
      }
     
    }
    cout << point<<endl;
    n--;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int ini = 0, out = 0, hit = 0, cnt = 0  ;
  while (ini <= n) {
    string s;
    cin >> s;
    if (s == "OUT") {
      out++;
      if (out == 3) {
        cout << cnt << endl;
        cnt = 0;
        hit = 0;
        out = 0;
        ini++;
      }
    }
    if (s == "HIT") {
      if (hit == 3) {
        cnt++;
      } else {
        hit++;
      }
    }

    if (s == "HOMERUN") {
      cnt += hit + 1;
      hit = 0;
    }
  }

}

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

using namespace std;

int main() {
	int base = 0;
	int out = 0;
	int score = 0;
	int inning;
	string evt;
	cin >> inning;
	while (inning) {
		cin >> evt;
		if (evt == "HIT") {
			base <<= 1;
			base |= 1;
			if (base > 7) {
				score++;
				base &= 7;
			}
		} else if (evt == "HOMERUN") {
			score++;
			for (int i = 0; i < 4; i++) {
				if ((base >> i) & 1) {
					score++;
				}
			}
			base = 0;
		} else {
			if (++out >= 3) {
				cout << score << endl;
				base = score = out = 0;
				inning--;
			}
		}
	}
	return 0;
}

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

int main(){
  int n,ansc=0,count=0,count1=0,count2=0,count3=0;
  string event[100];
  cin>>n;
  int i=0;
  while(1){
    cin>>event[i];
    if(event[i]=="OUT"){
      count++;
      count3++;
    }
    if(event[i]=="HIT")count1++;
    if(event[i]=="HOMERUN")count2++;
    if(count3==3*n)break;

    if(count==3){
      count=0;
      count1=0;
      count2=0;
    }
    else if(count2==1){
      ansc+=count1+1;
      count1=0;
      count2=0;
    }
    else if(count1==4){
      ansc++;
      count1--;
    }
    i++;
  }
    cout<<ansc<<endl;
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
int main(){
	int n,m=0,n2=0,s1=0,s2=0;
	std::cin>>n;
	int o=0;
	std::vector<int> vec(3);
	while(n>m){
		std::string str;
		std::cin>>str;
		if(str=="HIT"&&n2%2==0){
			
			if(vec[2]==1)s1++;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HIT"&&n2%2==1){
			if(vec[2]==1)s2++;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HOMERUN"&&n2%2==0){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s1++;
				vec[i]=0;
			}
			s1++;
		}
		if(str=="HOMERUN"&&n2%2==1){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s2++;
				vec[i]=0;
			}
			s2++;
		}
		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,n2++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	std::cout<<s1<<std::endl<<s2<<std::endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(int p=0; p < n; p++){
		int score = 0, out = 0, run[5];
		string event;
		fill(run, run+5, 0);

		while(1){
			cin >> event;
			if(event == "HIT"){
				run[0] = 1;
				for(int i=3; 0 <= i; i--){
					if(run[i] == 1) swap(run[i], run[i+1]);
				}
				if(run[4] == 1){
					score++;
					run[4] = 0;
				}
			}
			if(event == "HOMERUN"){
				run[0] = 1;
				for(int i=0; i < 4; i++){
					if(run[i] == 1){
						score++;
						run[i] = 0;
					}
				}
			}
			if(event == "OUT") out++;
			if(out == 3) break;
		}
		cout << score << endl;
	}
}

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

class Baseball {

	std::array<bool, 3> base;//base[0]:first, base[1]:second, base[2]:third
	int point,outcount,inning;

public:
	/*construtor*/
	Baseball(int ing) {
		for (int i = 0; i < (int)base.size(); ++i){
			base[i] = false;
		}
		point = 0;
		outcount = 0;
		inning = ing;
	}

	int inning_result(std::string res);

private:
	void clear();
	void hit();
	void homerun();
	void out();
};

/*Clear method*/
void Baseball::clear() {

	for (int i = 0; i < (int)base.size(); ++i){
		base[i] = false;
	}

	point = 0;
	outcount = 0;

}

/*The case of hit*/
void Baseball::hit() {

	if (base[2] == true) {
		++point;
		base[2] = false;
	}

	if (base[1] == true){
		base[2] = true;
		base[1] = false;
	}

	if (base[0] == true) {
		base[1] = true;
		base[0] = false;
	}

	base[0] = true;

}

/*The case of homerun*/
void Baseball::homerun() {

	++point;//butter runner point

	for (int i = 0; i < (int)base.size(); ++i){
		if (base[i] == true){
			++point;
		}
		base[i] = false;
	}

}

/*The case of out*/
void Baseball::out() {

	++outcount;

	if (outcount == 3){
		std::cout << point << std::endl;
		clear();
		--inning;
	}

}

/*Judgement of inning*/
int Baseball::inning_result(std::string res) {

	if (res == "HIT") {
		hit();
	}
	else if (res == "HOMERUN") {
		homerun();
	}
	else if (res == "OUT") {
		out();
	}
	else {
		std::perror(NULL);
	}

	return inning;
}

int main() {

	int n;//the number of ining
	std::string result;

	std::cin >> n;

	Baseball game(n);

	while (n > 0) {
		std::cin >> result;
		n = game.inning_result(result);
	}

	return 0;
}

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

using namespace std;

void outputAsBinary(unsigned char data)
{
	for(int i = 0;i < 8;i++)
	{
		if(data & (0x01 << i)) cout << "1";
		else cout << "0";
	}
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		int out = 0;
		int score = 0;
		unsigned char data = 0;
		while(1)
		{
			string event;
			cin >> event;
			if(event == "HIT")
			{
				data <<= 1;
				data |= 0x01;
				if(data & 0x08)
				{
					data &= ~0x08;
					score++;
				}
			}
			else if(event == "HOMERUN")
			{
				for(int i = 0;i < 3;i++)
				{
					if(data & (0x01 << i)) score++;
				}
				score++;
				data = 0;
			}
			else if(event == "OUT")
			{
				out++;
				if(out >= 3) break;
			}
			outputAsBinary(data);
		}
		cout << score << endl;
	}
	return 0;
}