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;

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{
			cout << point << endl;
			--count;
			point = 0;
			out_count = 0;
			base[0] = 0;
			base[1] = 0;
			base[2] = 0;
		}
		
		base[3] = 0;
	}
	
	return 0;
}

C++: #include <iostream>

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(){
		point = 0;
		out = 0;
		base = 0;
	}

	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();

		while(baseball.get_out() != 3){
			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();

		}

		std::cout >> baseball.get_point() >> std::endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n;
	string str;
	cin >> n;
	while(n--){
		int out=0,base[5]={},score=0;
		while(1){
			cin >> str;
			base[0] = 1;
			if(str=="OUT"){
				out++;
				if(out==3)	break;
			}
			else if(str=="HIT"){
				for(int i=4;i>=1;i--)	base[i]=base[i-1];
				if(base[4]>0){
					score++;
					base[4]=0;
				}
			}
			else{
				for(int i=0;i<4;i++){
					if(base[i]>0){
						score++;
						base[i] = 0;
					}
				}
			}
			//cout << base[1] << ' ' << base[2] << ' ' << base[3] << endl;
		}
		cout << score << endl;
	}
	return 0;
}

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

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner;
	
	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::getline(std::cin, str);
		
			if(str == "HIT")
				hit();
			else if(str == "OUT")
				out();
			else homerun();
		}
		
		return;
	}
	
	void hit(){
		int i;
		for(i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
		}
		++runner[i];
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
		++runner[3];
	}
	
	void show(){
		std::cout << runner[3] << std::endl;
	}
};

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1)

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    bool base[3] = {false};
    int point = 0, out = 0;
    while(1){
      char s[8];
      cin >> s;
      if(strcmp(s, "HIT") == 0){
        if(base[2] == true){
          point += 1;
          base[2] = false;
        }
        if(base[1] == true){
          base[1] = false;
          base[2] = true;
        }
        if(base[0] == true){
          base[0] = false;
          base[1] = true;
        }
        base[0] = true;
      }
      if(strcmp(s, "OUT") == 0){
        out++;
        if(out == 3)break;
      }
      if(strcmp(s, "HOMERUN") == 0){
        for(int j = 0; j < 3; j++){
          if(base[i] == true){
            base[i] = false;
            point++;
          }
        }
        point++;
      }
    }
    cout << point << endl;
  }
}

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

int main(void)
{
  int point;
  int single_hit=0;
  int homerun=0;
  int out=0;
  int inning;
  string event;

  cin >> inning;

  for(int i = 0 ; i < inning ; i++)
    {
      point = 0;
      while(1)
	{
	  if(out == 3) break;
	  
	  cin >> event;
	  if(event == "HIT") single_hit++;	  
	  if(event == "OUT") out++;
	  if(event == "HOMERUN") 
	    {
	      if(single_hit == 1) point+=2;
	      if(single_hit == 2) point+=3;
	      if(single_hit == 3) point+=4;
	      single_hit = 0;
	    }
	  if(single_hit == 4)
	    {
	      point++;
	      single_hit--;
	    }
	}
      cout << point << endl;
    }
  return 0;
}

C++: #include <stdio.h>

int main(void){
	int dataset,ining;
	int i;
	int runner[3],point,out;
	char str[8];

	scanf("%d",&dataset);
	for(ining=0;ining<dataset;ining++){

		//init state variable
		for(i=0;i<3;i++){
			runner[i]=0;
		}
		point=0;
		out=0;

		//start	ining
		while(out<3){
			scanf("%s",&str[0]);

			if(strcmp(str,"HOMERUN")==0){
		                for(i=0;i<3;i++){
					point+=runner[i];
		                        runner[i]=0;
		                }
				point++;
			}

			else if(strcmp(str,"HIT")==0){
				if(runner[2]==1){
					runner[2]=0;
					point++;
				}
				if(runner[1]==1){
					runner[1]=0;
					runner[2]=1;
				}
				if(runner[0]==1){
					runner[0]=0;
					runner[1]=1;
				}
				runner[0]=1;
			}

			else if(strcmp(str,"OUT")==0){
				out++;
			}
			printf("POINT:%d OUT:%d\n",point,out);
		}

		//finish ining
		printf("%d\n",point);
	}
}

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, score = 0;
	cin >> n;
	
	while(1) {
		char str[10];
		if(EOF == scanf("%s", str)) break;
		if(str == "OUT") {
			out++;
			if(out >= 3) {
				cout << score <<endl;
				score = out = base = 0;
				n--;
			}
		} else if(str == "HOMERUN") {
			score += base + 1;
			base = 0;
		} else {
			base++;
			if(base >= 4) {
				score++;
				base--;
			}
		}
	}
	cout << score << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n;
  string str;
  
  cin >> n;
  while (n--){
    int out = 0, base = 0, point = 0;
    while (out < 3){
      cin >> str;
      if (str == "HIT"){
        if (base < 3) base++;
        else point++;
      }
      else if (str == "HOMERUN"){
        point += base + 1;
        base = 0;
      }
      else out++;
    }
    cout << point << endl;
  }
}