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 <string>

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

	for (int i = 0; i < n; ++i) {
		int point = 0;
		int baseCount = 0;
		int outCount = 0;
		
		std::string str;
		while (outCount <= 2) {
			std::cin >> str;

			if (str == "HIT") {
				if (baseCount >= 3)
					++point;
				else
					++baseCount;
			}
			else if (str == "HOMERUN") {
				point += baseCount + 1;
				baseCount = 0;
			}
			else if (str == "OUT")
				++outCount;
		}

		std::cout << point << std::endl;
	}
}

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		int point = 0;
		bool base[3] = {false};
		int remain = 3;
		while(remain)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				if(base[2])
				{
					++point;
					base[2] = false;
				}
				for(int i = 1; i >= 0; --i)
				{
					if(base[i])
					{
						base[i + 1] = true;
					}
				}
				base[0] = true;
			}
			else if(str == "HOMERUN")
			{
				for(int i = 0; i < 3; ++i)
				{
					if(base[i])
					{
						++point;
					}
					base[i] = false;
				}
				++point;
			}
			else if(str == "OUT")
			{
				--remain;
			}
		}
		cout << point << endl;
	}
}

int main()
{
	solve();
	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;
		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;
			}
		}
		cout << score << endl;
	}
	return 0;
}

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

int main(){
  int n,ansc=0,o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;

  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;

    if(o2==3*n)break;

    if(h==4){
      ansc++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
    }
    else if(hr==1){
      ansc+=h+1;
      h=0;
      hr=0;
    }
    i++;
  }
  cout<<ansc<<endl;
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	int n;
	cin>>n;
	int count=3*n;
	int cint=0;
	while(n){
		int b[4]={0};
		int ten=0;
		while(cint!=3){
			cin>>a;
			if(a=="HIT"){
				for(int i=2;i>=0;i--){
						b[i+1]=b[i];
					}
					b[0]=1;
					if(b[3]==1){
						b[3]=0;
						ten++;
					}
			}
			if(a=="HOMERUN"){
				ten++;
				for(int i=0;i<3;i++){
					if(b[i]==1){
						ten++;
					}
					b[i]=0;
				}
			}
			if(a=="OUT"){
				cint++;
			}
		}
		cout<<ten<<endl;
		n--;
	}
}

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


int solve(){
  int base[4] = {0,0,0,0};
  int out = 0;
  int p = 0;
  while(out < 3){
    string s;
    cin>>s;

    //cout<<s<<endl;

    if(s == "HIT"){
      p += base[3];
      base[0] = 1;
      for(int i=3;i;i--){
        base[i] = base[i-1];
        base[i-1] = 0;
      }
    }else if(s== "OUT"){
      out++;
    }else if(s=="HOMERUN"){
      base[0]=1;
      for(int i=0;i<4;i++){
        p += base[i];base[i]=0;
      }
    }
    /*
    for(int i=0;i<4;i++){
      cout<<base[i];
    }cout<<" "<<p<<endl;
    */
  }

  return p;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cout<<solve()<<endl;
  }
}

C++: #include <iostream>

int main(void){
	bool firstRunner = false; //first runnner flag
	bool secondRunner = false; //second runnner flag
	bool thirdRunner = false; //third runnner flag

	int n; //number of data set
	std::cin >> n; //input number of data set

	while(n){
		int score = 0; //inning score
		int outCount = 0; //number of out count 

		while(outCount < 3){
			std::string str;
			std::cin >> str; //input event
		
			if(str == "HIT"){ //judge event
				//advance to the next base
				if(thirdRunner == true){
					++score;
					thirdRunner = false;
				}
				if(secondRunner == true){
					thirdRunner = true;
					secondRunner = false;
				}
				if(firstRunner == true){
					secondRunner = true;
				}
				firstRunner = true;
			}else if(str == "HOMERUN"){
				//add score
				if(thirdRunner == true){
					++score;
					thirdRunner = false;
				}
				if(secondRunner == true){
					++score;
					secondRunner = false;
				}
				if(firstRunner == true){
					++score;
					firstRunner =  false;
				}
				++score;
			}else if(str == "OUT"){
				//add out count
				++outCount;
			}
		}

		std::cout << score << std::endl; //output inning score
		--n;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string str;
		int base[5]={0};
		while(1){
			cin>>str;
			if(str=="HIT"){
				for(int j=3;j>=1;j--){
					if(base[j]==1){
						base[j+1]++;
						base[j]--;
					}
				}
				base[1]++;
			}else if(str=="HOMERUN"){
				for(int j=1;j<=3;j++){
					if(base[j]==1){
						base[4]++;
						base[j]--;
					}
				}
				base[4]++;
			}else if(str=="OUT"){
				base[0]++;
			}
			if(base[0]==3) break;
		}
		cout<<base[4]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

#define PI 4*atan(1)

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    bool base[3] = {false};
    int point = 0, out = 0;
    while(1){
      char s[8];
      cin >> s;
      if(strcmp(s, "HIT") == 0){
        if(base[2] == true){
          point += 1;
          base[2] = false;
        }
        if(base[1] == true){
          base[1] = false;
          base[2] = true;
        }
        if(base[0] == true){
          base[0] = false;
          base[1] = true;
        }
        base[0] = true;
      }
      if(strcmp(s, "OUT") == 0){
        out++;
        if(out == 3)break;
      }
      if(strcmp(s, "HOMERUN") == 0){
        for(int j = 0; j < 3; j++){
          if(base[j] == true){
            // cout << "base[" << i << "]" << endl;
            base[j] = false;
            point++;

          }
        }
        point++;
          // cout << "point:" << point << endl;
      }
    }
    cout << point << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[4],k=0,l=0;
  string s;
  cin>>n;
  while(k!=n){
    cin>>s;
    if(s=="HIT"){
      if(!a[0])a[0]++;
      else {
        if(!a[1])a[1]++;
        else{
          if(!a[2])a[2]++;
          else a[3]++;
        }
      }
    }
    else if(s=="OUT"){
      l++;
      if(l==3){
        a[1]=a[2]=a[0]=l=0;
        k++;
      }
    }
    else{
    a[3]+=1+a[1]+a[2]+a[0];
    a[1]=a[2]=a[0]=0;
    }
  }
  cout<<a[3]<<endl;
}