Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

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


using namespace std;

class Player{
private:
  int  base;

public:
  Player(int i){
    base=1;
  }


  void SetBase(int a){
    this->base =a;
  }

  int GetBase(){
    return this->base;
  }
};

class Baseball{
private:
  int score;
  int out;
  queue<Player> que;

public:
  Baseball(){
      score = out=0;
  }

  void add_hit(int num){
    Player one(1);
    this->que.push(one);
    int length=this->que.size();

    for(int i= 0;i<length;i++){
      Player tmp = this->que.front();
      this->que.pop();
      int tmp_base=tmp.GetBase();
      if((tmp_base+num)>4){
        score++;
      }else{
        tmp.SetBase(tmp_base+num);
        this->que.push(tmp);
      }
    }
  }

  void add_out(){
    this->out++;
  }

  void add_score(){
    this->score++;
  }

  int GetOut(){
    return this->out;
  }

  int GetScore(){
    return this->score;
  }

  void show_score(){
    cout<<this->score<<endl;
  }

};

int main(void){
  int time;
  cin >> time;

  for(int i=0;i<time;i++){
    Baseball baseball;
    while(baseball.GetOut()!=3){
      string judge;
      cin>>judge;
      if(judge == "HIT"){
        baseball.add_hit(1);
      }else if(judge=="OUT"){
        baseball.add_out();
      }else if(judge=="HOMERUN"){
        baseball.add_hit(4);
      }

      cout << judge << ' '<<baseball.GetOut()<<' '<<baseball.GetScore()<<endl;
    }

    cout<<baseball.GetScore()<<endl;
  }

  return 0;
}

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

int main(){
	int n,ining=0;
	int hit=0,out=0,count=0;
	std::cin>>n;
	while(ining!=n){
		std::string str;
		std::cin>>str;
		if(str=="HIT"){
			hit++;
			if(hit==4)hit=3,count++;
		}else if(str=="HOMERUN"){
			count+=hit+1;
			hit=0;
		}else if(str=="OUT"){
			out++;
			if(out==3){
				hit=0;
				out=0;
				ining++;
				std::cout<<count<<std::endl;
				count=0;
			}
		}
	}
	return 0;
}

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

int main(){
	int n;
	string str;
	cin >> n;
	while(n--){
		int ans = 0, out = 0, per = 0;
		while(1){
			cin >> str;
			if(str[1] == 'I'){
				per++;
				if(per > 3){per--;ans++;}
			}
			if(str[1] == 'O'){
				ans += per + 1;
				per = 0;
			}
			if(str[1] == 'U' && ++out == 3)break;
			//cout << per << ans << endl;
		}
		cout << ans << endl;
	}
}

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

int main(void){
	int n;
	cin>>n;
	while(n--){
		string s;
		valarray<int> h(3);
		int o=0;
		int sc=0;
		h=0;
		while(o!=3){
			cin>>s;
			if(s[0]=='O')o++;
			else if(s[1]=='I'){
				sc+=h[2];
				h=h.shift(1);
				h[0]=1;
			}else{
				sc+=1+h.sum();
				h=0;
			}
		}
		cout<<sc<<endl;
	}
	return 0;
}

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

int main()
{
	int n,inning=0;
	int p[40] = {0};
	string ivent;

	cin >> n ;
	while (1)
	{
		int r=0, o=3;                        //r = ???????????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p[inning]++;
                                        r=3;
				}
			}

			else if (ivent=="HORMRUN")
			{
				p[inning] += r + 1;
				r = 0;                            //??????????????????????????????
			}
			else if (ivent=="OUT")
			{
				o--;
			}
		}
                      
		inning++;
		if (n == inning) break;

	}

	for (int i = 0; i < n; i++)
	{
		cout << p[i] << endl;
	}

	return 0;
}

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

int main(){
	char input[10];
	int loc = 0, all = 0;
	int point = 0;
	int out = 3;
	int e;

	cin >> e;
	while(e != 0){
		cin >> input;
		if( strcmp(input, "HIT") == 0 ){
			loc++;
			if(loc > 3){
				loc--;
				point++;
			}
				
		}else if( strcmp(input, "OUT") == 0){
			out--;
			if(out == 0){
				out = 3;
				e--;
				loc = 0;
				cout << point << endl;
				point = 0;
			}
		}else if( strcmp(input, "HOMERUN") == 0){
			point++;
			point += loc;
			loc = 0;
		}
	}

}

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

int main()
{
	int n;
	string ivent;

	cin >> n ;
	while (n--)
	{
		int r=0, p=0, o=3;
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)
				{
					p++;
				}
			}

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)
				{
					p += 4;
				}
				else
				{
					p += r + 1;
				}
				r = 0;
			}
			else
			{
				o--;
			}
		}

		cout << p << endl;

	}


	return 0;
}

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

int n;
string eventType;
int point;
int outCount;
bool first, second, third;

void hit()
{
	point += third;
	third = second;
	second = first;
	first = true;
}
void homerun()
{
	point++;
	point += first;
	point += second;
	point += third;
	first = false;
	second = false;
	third = false;
}
void out()
{
	outCount++;
}

int main()
{
	cin >> n;
	while (n--)
	{
		point = 0;
		outCount = 0;
		first = false;
		second = false;
		third = false;

		while (true)
		{
			cin >> eventType;
			if (eventType == "HIT") hit();
			if (eventType == "HOMERUN") homerun();
			if (eventType == "OUT") out();

			if (outCount == 3)
			{
				cout << point << endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){
	int n; cin >> n ;
	int scoreA=0 ; int scoreB=0 ;
	for(int i=0;i<n;i++){
		int base=0; int out=0;string str; int score=0;
		while(1){
			cin >> str ;
			for(int i=0;str[i];i++) str[i]=toupper(str[i]);
			if(str=="OUT") out++;
			else if(str=="HIT") base++;
			else if(str=="HOMERUN") do{score+=++base; base=0;}while(0);
			if(out>=3) break;
			if(base>=4) do{base=3;score++;}while(0);
			};
		if(i%2==0) scoreA+=score; else scoreB+=score;
	};
	cout << scoreA << '\n' << scoreB << '\n' ;
}

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

int point;
int rui;
int oc;

void hit(){
  rui++;
  if(rui>3){
    point++;
    rui=3;
  }
}
void out(){
  oc++;
}

void home(){
  point+=1;
  point+=rui;
  rui=0;
}

int main(){
  int i,n;
  string event;
  point=0;
  rui=0;
  oc=0;

  cin >> n;
  for(i=0;i<n;i++){

    while(1){
      if(oc==3){
	rui=0;
	oc=0;
	break;
}
      cin >> event;
      if(event == "HIT"){
	hit();
      }else if(event == "OUT"){
	out();
      }else if(event == "HOMERUN"){
	home();
      }
    }
    cout << point << endl;
    point=0;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int score=0;
		int a=0,b=0,c=0;
		for(int out=0;out<3;)
		{
			string s;cin>>s;
			if(s=="HIT")
			{
				score+=c;
				c=b;
				b=a;
				a=1;
			}
			else if(s=="HOMERUN")
			{
				score+=a+b+c+1;
				a=b=c=0;
			}
			else
			{
				out++;
			}
		}
		cout<<score<<endl;
		
	}
}

C++: #include <iostream>
#include <string>
int main(void){
int datasets,i,hit=0,out,remain=0;
std::string input;
std::cin >> datasets;
for(i=0;i<datasets;++i){
	out=0;
	while(out<3){
		std::cin >> input;
		if(input=="HIT"){
			++hit;
			++remain;
		}
		if(input=="HOMERUN"){
			++hit;
			remain=0;
		}
		if(input=="OUT") ++out;
	}
	if(remain>3) remain=3;
	std::cout << hit-remain;
	hit=0;
	remain=0;
}
return 0;
}