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>

int main(int argc, const char * argv[]) {
    int k;
    int out = 0;
    int hit = 0;
    int numrun = 0;
    int pointa = 0;
    int pointb = 0;
    int ining = 0;
    
    std::cin >> ining;
    int i = 1;
    while(i < ining + 1){
        std::string judge;
        std::cin >> judge;
        
        if(judge == "HIT"){
            hit++;
            if(hit == 4){
                pointa++;
                hit = hit - 1;
            }
        }
        
        if(judge == "OUT"){
            out++;
            if(out >= 3){
                i++;
                std::cout << pointa << std::endl;
                hit = 0;
                out = 0;
                pointa = 0;
            }
        }
        
        if(judge == "HOMERUN"){
            pointa = pointa + hit + 1;
            hit = 0;
        }
  }
}

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;

}