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 <cstdio>

using namespace std;

int main(){
	
	int n, ans, out;
	
	string str;
	
	bool base[3];
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		
		base[0] = false;
		base[1] = false;
		base[2] = false;
		
		ans = 0;
		out = 0;
		
		while(true){
			
			cin >> str;
			
			if(str == "HIT"){
				if(base[2]){
					ans++;
				}
				if(base[1]){
					base[2] = true;
				}else{
					base[2] = false;
				}
				if(base[0]){
					base[1] = true;
				}else{
					base[1] = false;
				}
				base[0] = true;
			}else if(str == "HOMERUN"){
				ans++;
				if(base[2]){
					ans++;
				}
				if(base[1]){
					ans++;
				}
				if(base[0]){
					ans++;
				}
				base[0] = false;
				base[1] = false;
				base[2] = false;
			}else if(str == "OUT"){
				out++;
			}
			if(out >= 3){
				break;
			}
		}
		printf("%d\n", ans);
	}
	
	return 0;
}

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

class baseball{
    private:
    int runner; //number of runner
    int score; //score
    int out_count; //counter of out
    int third_base; //runner is or not
  
    public:
    void initial();
    int getScore();
    int getOutCount();
    void singleHit_1();
    void singleHit_2();
    void homerun();
    void out();
    
};

//initialize
void baseball::initial(){
    runner = 0;
    score = 0;
    out_count = 0;
    third_base = 0;
}

int baseball::getScore(){
    return score;
}

int baseball::getOutCount(){
    return out_count;
}

/*
update runner
 */
void baseball::singleHit_1(){
    if(runner < 3){
        ++runner;
    }
}

/*
increment of score
 */
void baseball::singleHit_2(){
    ++score;
}

/*
clear runner
and
add {(number of runner) + 1} to score
 */
void baseball::homerun(){
    score = score + (runner + 1);
    runner = 0;
}

/*
increment of out_count
 */
void baseball::out(){
    ++out_count;
}

int main(void){
    baseball bb;

    int n;
    std::cin >> n;

    std::string str;
    int count = 0; //counter of hit
    
    bb.initial();
    for(int i = 0; i < n; i++){
        while(bb.getOutCount() < 3){
	    std::cin >> str;
	    if(str == "HIT"){
	        ++count;
		if(count < 4){ //runner is less than 3
		    bb.singleHit_1();
		} else if(count >= 4){ //runner is 3
		    bb.singleHit_2();
		}
	    } else if(str == "HOMERUN"){
	        bb.homerun();
		count = 0;
	    } else if(str == "OUT"){
	        bb.out();
	    }
	}
	std::cout << bb.getScore() << std::endl;
	bb.initial();
	count = 0;
    }
    
    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();
		}
		
		std::cout << runner[3] << std::endl;
		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;
			}
		}
	}
};

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

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

class Baseball{
private:
	int point_count;
	int out_count;
	int runner;

public:
	 Baseball(int p, int o, int r);
	 void singleHit();
	 void homerun();
	 void out();
	 void newInning();
	 int now_point();
	 int now_out();
	~ Baseball();
};

Baseball::Baseball(int p, int o, int r){
	point_count = p;
	out_count = o;
	runner = r;
}

Baseball::~Baseball(){	
}

void Baseball::singleHit(){
	if(runner < 3){
		++runner;
	}else if(runner == 3){
		++point_count;
	}
}

void Baseball::homerun(){
	point_count += runner+1;
	runner = 0;
}

void Baseball::out(){
	++out_count;
}

void Baseball::newInning(){
	point_count = 0;
	out_count = 0;
	runner = 0;
}

int Baseball::now_point(){
	return point_count;
}

int Baseball::now_out(){
	return out_count;
}

int main(){
	int num;
	std::string event;
	Baseball baseball(0,0,0);

	std::cin >> num;

	for(int i=0; i<num; ++i){
		baseball.newInning();

		while(baseball.now_out() < 3){
			std::cin >> event;

			if(event == "HIT"){
				baseball.singleHit();

			}else if(event == "HOMERUN"){
				baseball.homerun();

			}else if(event == "OUT"){
				baseball.out();

			}
		}

		std::cout << baseball.now_point() << std::endl;
	}
	
}

C++: #include <stdio.h>
#include <string>

using namespace std;

int main(){
  int n;
  scanf("%d", &n);
  int c,o,r1,r2,r3;
  char event[16];
  for(int i=0;i<n;i++){
    c=o=r1=r2=r3=0;
    while(o!=3){
      scanf("%s", event);
      string e(event);
      if(e == "HIT"){
        c+=r3;
        r3=r2;r2=r1;r1=1;
      }else if(e == "HOMERUN"){
        c+=r3+r2+r1+1;
        r3=r2=r1=0;
      }else{
        o++;
      }
    }
    printf("%d\n", c);
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	int n;
	cin >> n;
	cin.ignore( 1 );

	REP( ni, 0, n )
	{
		int runner = 0, out = 0, point = 0;

		while ( out < 3 )
		{
			string e;
			cin >> e;

			if ( e == "HIT" )
			{
				runner++;
				if ( 4 <= runner )
				{
					point++;
					runner--;
				}
			}
			else if ( e == "HOMERUN" )
			{
				point += runner + 1;
				runner = 0;
			}
			else
			{
				out++;
			}
		}
		
		cout << point << endl;
	}

	return 0;
}

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

using namespace std;

int main(){
	int ening;
	cin>>ening;
	while(ening != 0){
		string result;
		int runner = 0;
		int score = 0;
		int out = 0;
		while(cin>>result){
			if(result == "HIT"){
					runner++;
					if(runner == 4){
						score+=1;
						runner=3;
					}
			}
			else if(result ==  "OUT"){
					out++;
			}
			else if(result == "HOMERUN"){
					score += runner + 1;
					runner = 0;
			}
			if(out == 3){
				break;
			}
		}
		cout<<score<<endl;
		ening -= 1;
	}
	return 0;
}