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 <queue>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n; cin>>n;
    while(n--){
        int out=0, p=0, b=0;
        while(out!=3){
            string s; cin>>s;
            if(s[0]=='O') out++;
            else if(s.back()=='T'){
                b++;
                if(b>=4) b--, p++;
            }
            else p+=b+1, b=0;
        }
        cout<<p<<endl;
    }
}

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){
					std::cout >> 7 >> std::endl;
					break;
				}
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int l,r,O,p,i;
string s;
int main(){cin>>l;
for(i=0;i<l;i++){p=0;O=0;r=0;
  while(O<3){cin>>s;
    if(s=="HOMERUN"){p+=r+1;r=0;}
    if(s=="OUT"){O++;}
    if(s=="HIT"){if(r==3){p++;}else{r++;}}
}cout<<p<<"\n";}}

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

int main(){
  int ining;
  vector<int> result;

  cin>>ining;

  for(int i=0;i<ining;++i){
    int out_count=0;
    int score=0;
    string event;
    bool first=false;
    bool second=false;
    bool third=false;
    
    while(out_count!=3){
      cin>>event;

      if(event=="HIT"){
	if(third==true){
	  third=false;
	  score++;
	}
	if(second==true){
	  third=true;
	  second=false;
	}
	if(first==true){
	  second=true;
	}
	first=true;
      }

      else if(event=="HOMERUN"){
	if(first==true && second==true && third==true){
	  score+=4;
	  first=false;
	  second=false;
	  third=false;
	}
	else if((first==true && second==true && third==false) ||
		(first==true && second==false && third==true) ||
		(first==false && second==true && third==true)){
	  score+=3;
	  first=false;
	  second=false;
	  third=false;
	}
	else if((first==true && second==false && third==false) ||
		(first==false && second==true && third==false) ||
		(first==false && second==false && third==true)){
	  score+=2;
	  first=false;
	  second=false;
	  third=false;
	}
	else if(first==false && second==false && third==false)
	  score++;
      }

      else if(event=="OUT")
	out_count++;
    }
    result.push_back(score);
  }
  for(auto i:result)
    cout<<i<<endl;
}

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

int main(){
	int n, point, runner, out;
	string input;
	cin >> n;
	for(int i = 0; i < n; i++){
		point = 0;
		runner = 0;
		out = 0;
		while(true){
			cin >> input;
			if(input=="HIT"){
				runner++;
				if(runner>3){
					point++;
					runner = 3;
				}
			}
			else if(input=="HOMERUN"){
				point = point + runner + 1;
				runner = 0;
			}
			else{
				out++;
				if(out==3){
					break;
				}
			}
		}
		cout << point << endl;
	}
	return 0;
}

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

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner; 	//first second third home
								//runner:1 no:0 home:point
	
	public:
	Baseball(){
		out_count = 0;
		for(int i=0; i<4; ++i)
			runner[i] = 0;
	}
	
	void ining(){
		while(out_count != 3){
			std::string str;
			std::cin >> str;
		
			if(str == "HIT") hit();
			else if(str == "OUT") out();
			else if(str == "HOMERUN") homerun();
		}
		
		std::cout << runner[3] << std::endl;
		return;
	}
	
	void hit(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
			if(i == 3)
				++runner[i];
		}
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<3; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
		++runner[3];
	}
};

int main(){
	int n;
	std::cin >> n;
	
	for(int k=0; k<n; ++k){
		Baseball game;
		game.ining();
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <bitset>
    
class Baseball{
    u_int score, out_count;
    std::bitset<4> runners; 
public:
    Baseball() : score(), out_count(){} //initializer list
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() {++out_count;}
    u_int getScore() {return score;}
    u_int getOutcount() {return out_count;}
};
   
void Baseball::hit(){
    runners <<= 1; //shift
    runners.set(0); //set runner
    if(runners.test(3)){
        ++score;
        runners.reset(3);
    }
}
   
void Baseball::homerun(){
    score += runners.count() + 1;
    runners.reset();
}
   
int main(){
    u_int inning;
    std::cin >> inning;
    for(u_int i = 0; i < inning; ++i){
        Baseball game;
        while(game.getOutcount() != 3){
            std::string event;
            std::cin >> event;
            if(event == "HIT"){
                game.hit();
            }else if(event == "HOMERUN"){
                game.homerun();
            }else if(event == "OUT"){
                game.out();
            }
        }
        std::cout << game.getScore() << std::endl;
    }
    return 0;
}

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

using namespace std;

int main(){
	int n,ct, score, out,run;
	string x;
	cin >> n;
	while (1){
		while (1){
			cin >> x;
			if (x == "OUT"){
				out++;
			}
			if (x == "HOMERUN"){
				score+=(run+1);
				run = 0;
			}
			if (x == "HIT"){
				run++;
			}
			if (run > 4){
				run--;
				score++;
			}
			if (out == 3){
				cout << score << endl;
				ct++;
				break;
			}
		}
		if (ct == n)break;
	}
	return 0;

}

C++: #include <iostream>
using namespace std;
int main( void )
{
	int n;
	cin >> n;

	int i = 0;

	int point = 0;
	int hit = 0;
	int now = 0;
	while ( i < n )
	{
		string s;
		cin >> s;
		if ( s == "OUT" )
		{
			now++;
		}
		else if ( s == "HIT" )
		{
			if ( hit >= 3 )
				point++;
			hit++;
		}
		else if ( s == "HOMERUN" )
		{
			point += hit + 1;
			hit = 0;
		}

		if ( now >= 3 )
		{
			cout << point << endl;
			now = 0;
			point = 0;
			hit = 0;
			i++;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int i,j,k,n,f1,f2,f3,h1,h2,h3;
	int out,hit,hran,v;
	char s[8];
	cin>>n;
	for(i=0;i<n;i++) {
		out=hit=hran=v=f1=f2=f3=0;
		while(1) {
			cin>>s;
			if(strcmp("HIT",s)==0) {
				h1=h2=h3=0;
				if(f1==0) f1=1,h1=1;
				if(f2==0&&f1==1&&h1==0) f2=1,h2=1;
				if(f3==0&&f2==1&&h2==0) f3=1,h3=1;
				if(f3==1&&h3==0) v++;
			}
			if(strcmp("HOMERUN",s)==0) {
				v+=(f1+f2+f3+1);
				f1=f2=f3=0;
			}
			if(strcmp("OUT",s)==0) {
				out++;
				if(out==3) {out=0;break;}
			}
		}
		cout<<v<<endl;
	}
}