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 <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>
using namespace std;

int main(){

  int n, out, runner, pt;
  string str, s;

  cin >> n;

  for(int i=0; i<n; i++){
    out = 0;
    runner = 0;
    pt = 0;
    while(out != 3){
      cin >> s;
      if(s == "OUT"){
        out++;
      }
      else if(s == "HOMERUN"){
        pt += runner + 1;
        runner = 0;
      }
      else{
        if(runner < 3) runner++;
        else pt++;
      }
    }

    cout << pt << endl;

  }  

  return 0;

}

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

using namespace std;

void baseball(){
    bool first=false, second=false, third=false;
    int runner=0;
    int outCount=0;
    int score=0;
    string event;
    string hit = "HIT";
    string homerun = "HOMERUN";
    string out = "OUT";
    
    while(outCount !=3){
        cin >> event;
        if(event == hit){
            if(third==true) runner--,score++;
            if(second==true) third=true;
            if(first==true) second=true;
            first=true;
            runner++;
        }
        else if(event == homerun){
            score += runner+1;
            first=false, second=false, third=false;
            runner=0;
        }
        else if(event == out){
            outCount++;
        }
        
    }
    cout << score<<endl;
}


int main(){
    
    int c;
    cin >> c;
    
    for(int i=0;i<c;i++){
        
        baseball();
        
    }
    return 0;
}

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

int main()
{
	int base[4]={},out_count=0,point=0;
	int count;
	string event;
	cin >> count;
	
	while(count){
		cin >> event;
		
		if(event == "HIT"){
			for(int i=3;i>=0;--i){
				base[i+1] += base[i];
				base[i] = 0;
			}
			++base[0];
		}
		
		if(event == "HOMERUN"){
			base[3] = base[0]+base[1]+base[2]+1;
			base[0] = 0;
			base[1] = 0;
			base[2] = 0;
		}
		
		if(event == "OUT"){
			++out_count;
		}
		
		if(out_count != 3){
			point += base[3];
			
		}else{
			--count;
			point = 0;
			out_count = 0;
			base[0] = 0;
			base[1] = 0;
			base[2] = 0;
			cout << point << endl;
		}
		
		base[3] = 0;
	}
	
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <bitset>

#define First 0x01
#define Second 0x01 << 1
#define Third 0x01 << 2
#define Run 0x01 << 3

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string str;
		int out = 0, score = 0;
		unsigned field = 0;
		while (out < 3) {
			cin >> str;
			if (str == "HIT") {
				field = field << 1;
				field |= First;
				if (field & Run) {
					score++;
					field &= ~(Run);
				}
			}
			else if (str == "HOMERUN") {
				score++;
				if (field & First) score++;
				if (field & Second) score++;
				if (field & Third) score++;
				field = 0;
			}
			else if (str == "OUT") {
				out++;
			}
		}
		cout << score << endl;
	}
	return 0;
}

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

int main(void)
{
  int n,a[40]={0},o,r,ct; //ctテ」ツ?ッテ」ツつ、テ」ツδ凝」ツδウテ」ツつーテヲツ閉ーテ」ツ?ョテァツョツ。テァツ青?
  string ivent;
  r=0;
  o=0;
  ct=0;
  
  cin >> n;
  while(1) { 
    cin >> ivent;
    if(ivent=="HIT") {
      r++;
      if(r>=4) {
	a[ct]++;
      } 
    } else if(ivent=="HOMERUN") {
      if(r<=3) { 
	a[ct]+=r+1;
      } else {
	a[ct]+=4;
      }
      r=0;

    } else if(ivent=="OUT") {
      o++;
      if(o==3) {
	ct++;
	o=0;
	r=0;      
      }  
    }
    if(ct==n) break;

  }

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

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

class Baseball{
private:
	int first;
	int second;
	int third;
	int score;
	int count;
public:
	Baseball(){
		first=0;
		second=0;
		third=0;
		score=0;
		count=0;
	}
	int score(){
		return score;
	}
	void hit(){
		score+=third;
		third=second;
		second=first;
		first=1;
	}
	void homerun(){
		score+=third+second+first+1;
		first=0;
		second=0;
		third=0;
	}
	void out(){
		count++;
	}
	int count(){
		return count;
	}
}

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

	for(int i=0;i<inning;i++){
		Baseball attack;
		std::string result;
		while(attack.count()<3){
			std::cin >> result;

			if(result == "HIT"){
				attack.hit();
			} else if(result == "HOMERUN"){
				attack.homerun();
			} else if(result == "OUT"){
				attack.out();
			}
		}
		std::cout << attack.score() <<std::endl;
	}

    return 0;
}

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

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

using namespace std;

int main() {
	int n;
	int base = 0, out = 0, count = 0;
	cin >> n;
	string str;
	while(scanf("%s", str) != EOF) {
		if(str == "OUT") {
			out++;
			cout << out << endl;
			if(out >= 3) {
				cout << count <<endl;
				count = out = base = 0;
				n--;
			}
		} else if(str == "HOMERUN") {
			count += base + 1;
			base = 0;
		} else {
			base++;
			if(base >= 4) {
				count++;
				base--;
			}
		}
	}
	cout << count << endl;
	return 0;
}

C++: #include <iostream>
#include <string>
 
class Baseball
{
    u_int runner, out, point;
     
public:
    Baseball();
    ~Baseball(){}
    
    u_int get_runner() const {return runner;}
    u_int get_out() const {return out;}
    u_int get_point() const {return point;}
    
    void game();
    void event_hit();
    void event_homerun();
    void event_out();
     
private:
    void set_runner(const u_int r) {runner = r;}
    void inc_runner() {++runner;}
    void inc_out() {++out;}
    void add_point(const u_int p) {point += p;}
};
 
Baseball::Baseball()
{
    runner = 0;
    out = 0;
    point = 0;
}

void Baseball::game()
{
    std::string event;
    while(get_out() != 3){
        std::cin >> event;
        if(event == "HIT"){
            event_hit();
        }
        else if(event == "HOMERUN"){
            event_homerun();
        }
        else{
            event_out();
        }
    }
} 

void Baseball::event_hit()
{
    if(get_runner() == 3){
        add_point(1);
    }
    else{
        inc_runner();
    }   
}
 
void Baseball::event_homerun()
{
    add_point(1 + get_runner());
    set_runner(0);
}
 
void Baseball::event_out()
{
    inc_out();
}
 
int main()
{
    u_int inning;
    std::cin >> inning;
     
    for(u_int i = 0; i < inning; ++i){
        Baseball b_ball;
        b_ball.game();
        std::cout << b_ball.get_point() << std::endl;
    }
 
    return 0;
}