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 "bits/stdc++.h"
using namespace std;
int main() {
	int N; cin >> N;
	while (N--) {
		int score = 0;
		int out = 0;
		int run = 0;
		while (out <= 2) {
			string st; cin >> st;
			if (st == "OUT")out++;
			else if (st == "HIT") {
				run++;
				if (run > 3) {
					run = 3;
					score++;
				}
			}
			else {
				score += 1 + run;
				run = 0;
			}
		}
		cout << score << endl;
	}
	return 0;
}

C++: #define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 11
#define HO 6
int main(void)
{
	int n;
	string out = { "OUT" }, hit = { "HIT" }, homerun = { "HOMERUN" };
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		int out_cou = 0, point = 0;
		bool rui[4] = { 0 };
		while (out_cou < 3) {
			string ev;
			cin >> ev;
			if (ev == hit) {
				rui[0] = true;
				for (int i = 3; i >= 1; --i) {
					if (rui[i] == true && i == 3) { ++point; rui[i] = false; }
					if (rui[i - 1] == true) { rui[i] = true; rui[i - 1] = false; }
				}
			}
			else if (ev == out) {
				++out_cou;
			}
			else if (ev == homerun) {
				for (int i = 1; i < 4; ++i) {
					if (rui[i] == true) { ++point; }
					rui[i] = false;
				}
				++point;
			}
		}
		printf("%d\n", point);
	}
}

C++: #include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int out = 0;
    int point = 0;
    int r1 = 0, r2 = 0, r3 = 0;
    while (out <= 2) {
      string str;
      cin >> str;
      if (str == "HIT") {
        if (r3) point++;
        r3 = r2; r2 = r1; r1 = 1;
      } else if (str == "OUT") {
        out++;
      } else if (str == "HOMERUN") {
        point += r1 + r2 + r3 + 1;
        r1 = r2 = r3 = 0;
      }
    }
    cout << point << endl;
  }

  return 0;
}

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

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        bool r[3]={false};
        int res=0;
        for(int o=0;o!=3;){
            string buf;
            cin>>buf;
            if(buf=="HIT"){
                if(r[2]){
                    r[2]=false;
                    res++;
                }
                if(r[1]){
                    r[1]=false;
                    r[2]=true;
                }
                if(r[0]){
                    r[0]=false;
                    r[1]=true;
                }
                r[0]=true;
            }
            if(buf=="HOMERUN"){
                for(int j=0;j<3;++j){
                    if(r[j]){
                        r[j]=false;
                        res++;
                    }
                }
                res++;
            }
            if(buf=="OUT"){
                o++;
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

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

using namespace std;

// 最初の入力：イニング数
// 1イニングは3アウトになるまで
// シングルヒットの場合
// 1つずつ押し出されるため、走者は消えない。
// 3塁に走者がいる場合は1点を返す。
// ホームランの場合
// 1点＋走者の数。走者はすべて消滅

// 塁の状態を管理する
struct Diamond {
	bool first;
	bool second;
	bool third;
	Diamond() : first(), second(), third(){};

	int onHit() {
		int result = 0;
		if (third != false) {
			result = 1;
		}
		if (second != false) {
			third = true;
		}
		if (first != false) {
			second = true;
		}
		first = true;
		return result;
	}
	int onHomeRun() {
		// 最低でも1点なので1で初期化
		int result = 1;
		if (third != false) {
			result++;
		}
		if (second != false) {
			result++;
		}
		if (first != false) {
			result++;
		}
		first = false;
		second = false;
		third = false;
		return result;
	}
};

int main() {

	int n;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		int out_count = 0;
		int point = 0;
		Diamond dia;
		while (out_count < 3) {
			string temp;
			cin >> temp;

			if (temp == "HIT") {
				point += dia.onHit();
			}
			else if (temp == "HOMERUN") {
				point += dia.onHomeRun();
			}
			else {
				// その他をOUTとしておく。
				out_count++;
			}
		}
		cout << point << endl;
	}
	return 0;
}

C++: #include <string>
#include <iostream>
using namespace std;
int N, c1, c2, c3, out, ret; string S;
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		c1 = 0, c2 = 0, c3 = 0, out = 0, ret = 0;
		while (out != 3) {
			cin >> S;
			if (S == "HIT") {
				ret += c3, c3 = c2, c2 = c1, c1 = 1;
			}
			else if (S == "HOMERUN") {
				ret += c1 + c2 + c3, c1 = 0, c2 = 0, c3 = 0;
			}
			else {
				out++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b=0;
  int out=0,point=0;
  string c;
  cin>>a;
  while(true){
    if(a==0) break;
    cin>>c;
    if(c=="HIT"){
      b++;
      if(b==4){
	point++;
	b--;
      }
    }
    if(c=="OUT"){
      out++;
      if(out==3){
	a--;
	out=0;
	cout<<point<<"\n";
	point=0;
	b=0;
      }
    }
    if(c=="HOMERUN"){
      point=point+b+1;
      b=0;
    }
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void)
{
	int score = 0;
	int runner = 0;
	int out = 0;
	int inning = 1;
	int inning_limit;
	cin>>inning_limit;
	int inning_score[34] = {};
	bool rui_1 = false;
	bool rui_2 = false;
	bool rui_3 = false;
	string hit[100];
	int i = 0;
	
	while(cin>>hit[i]){
		if(hit[i] == "HIT"){
			if(rui_3==true){
				inning_score[inning]++;
				
			}else{
				runner++;
			}
			rui_3 = rui_2;
			rui_2 = rui_1;
			rui_1 = true;
			runner++;
		}else if(hit[i] == "HOMERUN"){
			inning_score[inning] += runner + 1;
			runner = 0;
			rui_1=false;
			rui_2=false;
			rui_3=false;
		}else if(hit[i] == "OUT"){
			out++;
			if(out== 3){
				inning++;
				runner = 0;
				out = 0;
				inning_score[inning + 1] = 0; 
				rui_1=false;
				rui_2=false;
				rui_3=false;
				score += inning_score[inning];
				if(inning > inning_limit){
					break;
				}
			}
		}
		i++;
	}

	for(int j = 1; j <= inning_limit;j++){
		cout<<inning_score[j]<<endl;
	}

	return 0;
}

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

int main(){
  int n,ansc[100]={},o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;
  int j=0;
  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;

    if(o2==3*n)break;

    if(h==4){
      ansc[j]++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
      j++;
    }
    else if(hr==1){
      ansc[j]+=h+1;
      h=0;
      hr=0;
    }
    i++;
  }
  for(int j=0;j<n;j++)
  cout<<ansc[j]<<endl;
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int
using namespace std;

int main()
{
	int n;
	int base[3], out, point;
	string ev;

	cin >> n;
	for(int i=0; i<n; i++){
		point = 0;
		out = 0;
		base[0] = base[1] = base[2] = 0;
		while(out < 3){
			cin >> ev;
			if(ev == "OUT") out++;
			else if(ev == "HOMERUN"){
				point += base[0] + base[1] + base[2] + 1;
				base[0] = base[1] = base[2] = 0;
			} else {
				if(base[2] == 1) point++;
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			}
		}
		cout << point << endl;
	}

	return 0;
}