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 <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;
        }
    }
    
    //ホームラン
    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);
        }
    }
}

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

using namespace std;
typedef long long ll;

int main(){
    int n;
    string S;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        
        int h=0,point=0,o=0;
        
        while(1){
            cin >> S;
            
            if(S == "HIT"){
                if(h>=3)
                    point++;
                else
                    h++;
            }else if(S == "HOMERUN"){
                point+=h+1;
                h=0;
            }else if(S == "OUT"){
                o++;
            }
            
            if(o>=3) break;
        }
        
        printf("%d\n",point);
    }
    
    return 0;
}

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

int main(){
	bool F,S,T	//???
	int out,point;
	
	int i,j;
	
	int dataN,dataLoop;
	string E;	//????????????
	
	cin>>dataN;
	for(dataLoop=0;dataLoop<dataN;dataLoop++){
	//????????????
	out=0;point=0;
	while(out==3){
	 cin>>E;
	 switch(E){
		case "HIT":
		if(T){point++;}
		T=S;S=F;F=true;
		break;
		case "HOMERUN":
		point++;
		if(F){point++;F=false;}
		if(S){point++;S=false;}
		if(T){point++;T=false;}
		break;
		case "OUT":
		out++;
		break;
	 }
	}
	cout<<point<<endl;
	//???????????§
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
 
class Baseball{
	int score, out_count;
	std::queue<bool> runners;
public:
	Baseball() : score(), out_count(){}
	void hit();
	void homerun();
	void out();
	int get_score() {return score;}
	int get_out() {return out_count;}
};

void Baseball::hit(){
	runners.push(true);
	if(runners.size() == 4){
		++score;
		runners.pop();
	}
}

void Baseball::homerun(){
	score += runners.size() + 1;
	while(!runners.empty()){
		runners.pop();
	}
}

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

int main(){
	int inning;
	std::cin >> inning;
	for(int i = 0; i < inning; ++i){
		Baseball game;
		while(game.get_out() != 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.get_score() << std::endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<edge> edges;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n;
	cin >> n;
	REP(x, n)
	{
		string s;
		int cntout = 0;
		int run = 0;
		while (cin >> s)
		{
			if (s == "OUT") cntout++;
			if (cntout == 3)
			{
				int sum = 0;
				run >>= 3;
				while (run > 0)
				{
					if (run & 1) sum++;
					run >>= 1;
				}
				cout << sum << endl;
				break;
			}
			if (s == "HIT")
			{
				run <<= 1;
				run += 1;
			}
			if (s == "HOMERUN")
			{
				run <<= 1;
				run += 1;
				run <<= 3;
			}
		}
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	rep(i, n) {

		int Point = 0, Out = 0;
		VI rui(3);

		while (Out != 3) {
			string s; cin >> s;

			if (s == "HIT") {
				Point += rui[2];
				rui[2] = rui[1];
				rui[1] = rui[0];
				rui[0] = 1;
			}
			else if (s == "HOMERUN") {
				Point += rui[0] + rui[1] + rui[2] + 1;
				rui[0] = 0; rui[1] = 0; rui[2] = 0;
			}
			else if (s == "OUT") {
				Out++;
			}
		}

		Cout(Point);
	}
}

C++: b,s,o;main(a){for(scanf("%*d");~scanf("%s",&a);b=a%3?(a%3-2)?b+1:o?b:(s=!printf("%d\n",s+((b>3)?b-3:0))):!(s+=++b))a%3-2||(o=(o+1)%3);}

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

using namespace std;

int base=0;
int score = 0;
int out=0;

void addRunner(){
	switch (base){
	case 0:base = 1; break;
	case 1:base = 11; break;
	case 10:base = 101; break;
	case 11:base = 111; break;
	case 100:base = 1; score++; break;
	case 101:base = 11; score++; break;
	case 111:base = 111; score++; break;
	default:printf("any error"); break;
	}
}

int main(){
	int cining=0,ining;
	char eventName[9];

	cin >> ining;

	for (int i = 0; i < 100; i++){
		cin >> eventName;
		if (strcmp("HIT", eventName) == 0){
			addRunner();
		}
		else if (strcmp("OUT",eventName) == 0){
			out++;
			if (out == 3){
				printf("%d\n", score);
				score = out = base = 0;
				cining++;
				if (cining == ining)break;
			}
		}
		else if (strcmp("HOMERUN", eventName) == 0){
			switch (base){
			case 0:score++; break;
			case 1:score += 2; break;
			case 10:score += 2; break;
			case 11:score += 3; break;
			case 100:score += 2; break;
			case 101:score += 3; break;
			case 110:score += 3; break;
			case 111:score += 4; break;
			default:printf("any error"); break;
			}
			base = 0;
		}
	}

	return 0;
}