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 n,ansc=0,o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;

  while(1){
    cin>>event;
    cout<<event<<endl;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;
    if(o2==3*n)break;

    if(h==4){
      ansc++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
    }
    else if(hr==1){
      ansc+=h+1;
      h=0;
      hr=0;
    }
  }
  i++;
  cout<<ansc<<endl;
return 0;
}

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

int main(void){

	int sum,out;
	int runner[3];
	char act[8];
	int n;
	int i,j;

	scanf("%d",&n);

	for(i=0;i<n;i++){

		sum = 0;
		out = 0;
		runner[0] = runner[1] = runner[2] = 0;

		while(out < 3){

			scanf("%s",act);

			if(strcmp("HIT",act) == 0){
				if(runner[2] == 1)
					runner[2] = 0,sum++;
				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("HOMERUN",act)==0){
				sum++;

				for(j=0;j<3;j++){
					if(runner[j] == 1){
						runner[j] = 0;
						sum++;
					}
				}
			}
			else if(strcmp("OUT",act)==0){

				out++;
			}
		}

		printf("%d\n",sum);

	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef struct{
    int count;
    string s="OUT";
}OUT;
typedef struct{
    int count;
    string s="HOMERUN";
}HOME;
typedef struct{
    int count;
    string s="HIT";
}HIT;
typedef struct{
    int count;
}RUN;
typedef pair<int, int> pii;
int main(){
    int n; cin>>n;
    pii score=pii(0,0); bool now=1;
    OUT out; HOME home; HIT hit; RUN run;
    out.count=0; home.count=0; hit.count=0; run.count=0;
    string temp;
    while(cin>>temp){
        if(temp==out.s){out.count++; if(out.count==(3*n))goto E;if(out.count%3==0){if(now)now=0; else now=1;run.count=0;}}
        if(temp==home.s){
            if(now)score.first+=run.count+1;
            else score.second+=run.count+1;
            run.count=0;
        }
        if(temp==hit.s){
            run.count++;
            if(run.count>3){if(now)score.first++;else score.second++; run.count-=1;}
        }
    }
E:;cout<<score.first<<"\n"<<score.second<<endl;
}

C++: #include <stdio.h>
#include<string>
#include<iostream>
using namespace std;
int base[4];
int point;
int out_count;

void format(){
	int i;
	for(i=3;i--;){
		base[i]=0;
	}
	point=0;
	out_count=0;
}

void hit(){
	int i;
	for(i=3;i--;){
		if(base[i-1]==1){
			base[i]=1;
		}
		base[0]=1;
		
		if(base[3]==1){
			point++;
			base[3]=0;
		}
		
	}
}

void homerun(){
	int i;
	for(i=3;i--;){
		if(base[i]==1){
			point++;
			base[i]=0;
		}
	}
}


int main(){
	format();
	int n;
	scanf("%d",&n);
	
	string s;
	while(n>0){
		cin >> s;
		
		if(s=="OUT"){
			out_count++;
		}else if(s=="HIT"){
			hit();
		}else if(s=="HOMERUN"){
			homerun();
		}else{
			printf("error");
		}
		
		if(out_count==3){
			printf("%d\n",point);
			n--;
			format();
		}
		
		
	}
	
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int o = 0;
		int point = 0;
		int stt[3] = { 0 };
		while (o < 3){
			string s;
			cin >> s;
			if (s.compare("HIT") == 0) {
				if (stt[2] == 1) {
					point++;
				}
				for (int j = 2; j > 0; j--) {
					stt[j] = stt[j - 1];
				}
				stt[0] = 1;
			} else if (s.compare("HOMERUN") == 0) {
				for (int j = 0; j < 3; j++) {
					if (stt[j] == 1) {
						point++;
					}
					stt[j] = 0;
				}
				point++;
			} else if (s.compare("OUT") == 0) {
				o = o++;
			}
		}
		cout << point << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<string> a(1001);
    bool run[30]={false, false, false};
    int out=0, e=0;
    int point[500] = {};
    int j=0;
    int k=0;
    while(cin >> a[j]) {
        if(a[j]=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a[j]=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        j++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }
 
}

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

int base[3] = { 0, 0, 0 };
int out = 0;
int score = 0;
int n;
string event[100];
int eventnum = 0;
int a = 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 j = 0; j < 3; j++)
	{
		base[j] = 0;
	}
}

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

		}
	}

	for (int i = 0; i < eventnum; i++)
	{
		if (event[i] == "HIT")
		{
			if (base[2] == 1)
			{
				score += 1;
			}
			Hit();
		}
		else if (event[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;
			}
		}
	}
}