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>
 
using namespace std;
 
// ???????????\?????????????????°??°
// 1???????????°???3??¢????????????????????§
// ????????°?????????????????´???
// 1??????????????????????????????????????°???????¶?????????????
// 3????????°??????????????´??????1???????????????
// ????????????????????´???
// 1????????°????????°?????°????????????????¶????
 
// ????????¶??????????????????
struct Diamond {
    bool first;
    bool second;
    bool third;
    Diamond() : first(), second(), third(){};
 
    int onHit() {
        int result = 0;
        if (third != false) {
            result = 1;
        }
        if (second != false) {
            third = true;
        }
        if (first != false) {
            second = true;
        }
        first = true;
        return result;
    }
    int onHomeRun() {
        // ????????§???1???????????§1??§?????????
        int result = 1;
        if (third != false) {
            result++;
        }
        if (second != false) {
            result++;
        }
        if (first != false) {
            result++;
        }
        first = false;
        second = false;
        third = false;
        return result;
    }
};
 
int main() {
 
    int n;
 
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int out_count = 0;
        int point = 0;
        Diamond dia;
        while (out_count < 3) {
            string temp;
            cin >> temp;
 
            if (temp == "HIT") {
                point += dia.onHit();
            }
            else if (temp == "HOMERUN") {
                point += dia.onHomeRun();
            }
            else {
                // ????????????OUT??¨???????????????
                out_count++;
            }
        }
        cout << point << endl;
    }
    return 0;
}

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

int main() {
	int n;
	int score=0;
	int count=0;
	int base=0;
	string d;
	cin>>n;
	for(int i=0;i<n;i++){
		while(true){
			cin>>d;
			if(d=="HIT"){
				base++;
				if(base==4){
					score++;
					base--;
				}
			}
			else if(d=="HOMERUN"){
				score=score+base+1;
				base=0;
			}
			else if(d=="OUT"){
				count++;
				if(count==3){
					count=0;
					cout<<score<<endl;
					score=0;
					base=0;
					break;
				}
			}
		}
	}
	return 0;
}

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){
				break;
			}
		}

	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int outcount=3,runner=0,point=0;
        while(outcount){
            string kind;
            cin>>kind;
            if(kind=="HIT")runner++;
            else if(kind=="HOMERUN"){
                point+=runner+1;
                runner=0;
            }
            else outcount--;

            if(runner>3){
                point++;
                runner--;
            }
        }
        cout<<point<<endl;

    }
    return 0;
}

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

using namespace std;

int main()
{
  int count;
  int out_count = 0;
  int first = 0;
  int second = 0;
  int third = 0;
  int point = 0;

  string h = "HIT";
  string o = "OUT";
  string home = "HOMERUN";

  cin>>count;

  while(1){
    string v;
    cin>>v;

    if(v == o){
      ++out_count;
      if(out_count%3 == 0){
        cout<<point<<endl;
        point = 0;
        first = 0;
        second = 0;
        third = 0;
      }
      if(out_count == count*3){
        break;
      }
    }
    else if(v == h){
      if(third == 1){
        point += 1;
        third = 0;
      }
      if(second == 1){
        third = 1;
        second = 0;
      }
      if(first == 1){
        second = 1;
      }
      first = 1;
    }
    else if(v == home){
      if(third == 1){
        point += 1;
        third = 0;
      }
      if(second == 1){
        point += 1;
        second = 0;
      }
      if(first == 1){
        point += 1;
        first = 0;
      }
      ++point;
    }
  }
  return 0;
}

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

using namespace std;

int main(){
	int n=0,ct=0, score=0, out=0,run=0;
	string x;
	cin >> n;
	while (1){
		int  score = 0, out = 0, run = 0;
		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<stdio.h>
#include<string.h>
main(){
  int n;
  int out=0,hit=0,total_out=0;
  int point=0;
  char ibe[10];
  scanf("%d",&n);
  while(total_out!=3*n){
    scanf("%s",ibe);
    if(strcmp(ibe,"HIT")==0){
      hit++;
    }
    if(hit==4){
      point++;
      hit=3;
    }
    if(strcmp(ibe,"OUT")==0){
      out++;
      total_out++;
    }
    if(strcmp(ibe,"HOMERUN")==0){
      point+=hit+1;
      hit=0;
    }
    if(out==3){
      out=0;
      hit=0;
      printf("%d\n",point);
      point=0;
    }
  }
  return 0;
}

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


class Baseball {
public:
    int score;                //得点
    int count;                //アウトカウント
    std::queue<int> runner;   //ランナー

    //コンストラクタ
    Baseball(int sc,int co){
        score = sc;
        count = co;
        while(!runner.empty()){
            runner.pop();
        }
    }
    
    //ヒット
    void hit(){
        if(runner.size() == 3){
            ++score;
        }
        runner.push(1);
    }
    
    //ホームラン
    void homerun(){
        while(!runner.empty()){
            ++score;
            runner.pop();
        }
        ++score;;
    }
    
    //アウト
    void out(){
        ++count;
    }
};


int main(){
    int n;
    std::string event;
    
    std::cin >> n;
    
    Baseball game(0,0);
    
    while(n > 0 && std::cin >> event){
        if(event =="HIT")
            game.hit();
        else if(event == "HOMERUN")
            game.homerun();
        else
            game.out();
        
        if(game.count == 3){
            --n;
            std::cout << game.score << std::endl;
            game = Baseball(0,0);
        }
    }
}