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 out = 0;
	int r1 = 0;
	int r2 = 0;
	int r3 = 0;
	int t = 0;
	string k;
	int a = 0;
	cin >> a;
	for (int i = 1; i <= a; i++)
	{
		out = 0;
		t = 0;
		r1 = 0;
		r2 = 0;
		r3 = 0;
		while (out != 3)
		{
			cin >> k;
			if (k == "OUT")
			{
				out++;
			}
			if (k == "HIT")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					r3 = 1;
					r2 = 0;
				}
				if (r1 == 1)
				{
					r2 = 1;
					r1 = 0;
				}
			}
			if (k == "HOMERUN")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					t++;
					r2 = 0;
				}
				if (r1 == 1)
				{
					t++;
					r1 = 0;
				}
				t++;

			}
		}
		cout << t << endl;
	}
	return 0;
}

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

int main(){
	char input[10];
	int loc = 0, all = 0;
	int point = 0;
	int out;
	int gar;

	cin >> gar;
	out = 3;
	while(gar != 0){
		cin >> input;
		if( strcmp(input, "HIT") == 0 ){
			loc++;
			if(loc > 3){
				loc--;
				point++;
			}
				
		}else if( strcmp(input, "OUT") == 0){
			out--;
			if(out == 0){
				out = 3;
				gar--;
				loc = 0;
			}
		}else if( strcmp(input, "HOMERUN") == 0){
			point++;
			point += loc;
			loc = 0;
		}
	}
	cout << point << endl;

}

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;
        }
        else
            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);
        }
    }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n;
  cin>>n;
  int out=0;
  int score;
  string a;
  bool rui[3]={0};
  for(int i=0;i<n;i++){
    out=0; score=0;
    for(int j=0;j<3;j++){
      rui[j]=false;
    }
    while(out<3){
      cin>>a;
      if(a=="OUT")out++;
      if(a=="HIT"){
	if(rui[2]){rui[2]=false;score++;}
	if(rui[1]){rui[1]=false;rui[2]=true;}
	if(rui[0]){rui[0]=false;rui[1]=true;}
	rui[0]=true;
      }
      if(a=="HOMERUN"){
	score++;
	for(int j=0;j<3;j++){
	  if(rui[j]){rui[j]=false;score++;}
	}
      }
    }
    cout<<score<<endl;
  }
}

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

int base[3] = {0, 0, 0};

void Hit()
{
	if (base[2] == 1)
	{
		base[2] = 0;
	}
	if (base[1] == 1)
	{
		base[2] = 1;
	}
	if (base[0] == 1)
	{
		base[1] = 1;
	}
	else if (base[0] == 0)
	{
		base[0] = 1;
	}

}

void Homerun()
{
	for (int i = 0; i < 3; i++)
	{
		base[i] = 0;
	}
	
}

int main()
{
	int out = 0;
    int score = 0;
	int n;
	string s;
    vector <string> event;
	int eventnum = 0;

	cin >> n;
	int a = 0;
	for (int i = 0; i < 3 * n; i++)
	{
		while (true)
		{
			cin >> s;
			event.push_back(s);
			if (event.at(a) == "OUT")
			{
				a += 1;			
				eventnum += 1;
				break;
			}
			else
			{
				a += 1;
				eventnum += 1;
			}

		}
	}

	for (int i = 0; i < eventnum; i++)
	{
		if (event.at(i) == "HIT")
		{
			if (base[2] == 1)
			{
				score += 1;
			}
			Hit();
		}
		else if (event.at(i) == "HOMERUN")
		{
			score += base[0] + base[1] + base[2] + 1;
			Homerun();
		}
		else
		{
			out += 1;
			if (out == 3)
			{
				cout << score << endl;
				for (int i = 0; i < 3; i++)
				{
					base[i] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}

	return 0;
}

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

int main(){

  int n;
  cin >> n;
  while(n){
    int out = 0,hit = 0,point= 0;
    while(out != 3){
      string s;
      cin >> s;
      if(s == "OUT") out++;
      else if(s == "HIT"){
	hit++;
	if(hit == 4){
	  point++;
	  hit = 3;
	}
      }
      else if(s == "HOMERUN"){
	point += hit + 1;
	hit = 0;
      }
     
    }
    cout << point<<endl;
    n--;
  }
  return 0;
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string a;
    int b,p,o;
    while(n--, n>=0){
        b = p = o = 0;
        while( cin >> a){
            if (a=="HIT"){
                b += 1;
                if (b >= 4){
                    b = 3;
                    p += 1;
                }
            } else if (a=="OUT"){
                o += 1;
                if (o >= 3) {
                    printf("%d\n",p);
                    break;
                }
            } else if (a=="HOMERUN"){
                p += b+1;
                b = 0;
            }
        }
    }
    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(1) {
		if(EOF == scanf("%s", str)) break;
		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>
#include <cstring>
using namespace std;

int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		int count = 0,out = 0;
		int home[4];
		memset(home,0,sizeof(home));
		while(out != 3)
		{
			string s;
			cin >> s;

			if(s == "OUT")
			{
				out++;
			}
			else if(s == "HIT")
			{
				if(home[2] == 1)
				{
					home[2]--;
					home[3]++;
				}
				if(home[1] == 1)
				{
					home[1]--;
					home[2]++;
				}
				if(home[0] == 1)
				{
					home[0]--;
					home[1]++;
				}

				home[0]++;
			}
			else if(s == "HOMERUN")
			{
				if(home[2] == 1)
				{
					home[2]--;
					home[3]++;
				}
				if(home[1] == 1)
				{
					home[1]--;
					home[3]++;
				}
				if(home[0] == 1)
				{
					home[0]--;
					home[3]++;
				}
				home[3]++;
			}
		}
		count = home[3];
		cout << count << endl;
	}
	return 0;
}