Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

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

int main()
{
  int n;
  string str;

  cin >> n;
  while (n--){
    int res = 0, o_ct = 0, ct = 0;
    while (true){
      cin >> str;
      if (str == "OUT"){
        o_ct++;
        if (o_ct == 3)  break;
      }
      else if (str == "HOMERUN"){
          res += ct + 1;
          ct = 0;
      }
      else {
        if (ct + 1 == 4)  res++;
        else ct++;
      }
    }
    cout << res << endl;
  }
}

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

class Baseball {
	private:
		int out;
		int runner;
		int point;
		
	public:
		Baseball(){
			out = 0;
			runner = 0;
			point = 0;
		}
		
		int getOut(){
			return out;
		}
		void addOut(){
			++out;
		}
		
		void hit(){
			++runner;
			if(runner == 4){
				++point;
				--runner;
			}
		}
		void homerun(){
			point += runner + 1;
			runner = 0;
		}
		
		int getRunner(){
			return runner;
		}
		
		int getPoint(){
			return point;
		}
};

int main(){
	int inning;
	std::cin >> inning;
	
	for(int i=0; i<inning; ++i){
		Baseball bs;
		
		while(bs.getOut() < 3){
			std::string str;
			std::cin >> str;
			
			if(str == "HIT"){
				bs.hit();
			}
			if(str == "HOMERUN"){
				bs.homerun();
			}
			if(str == "OUT"){
				bs.addOut();
			}
		}
		std::cout << bs.getPoint() << std::endl;
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main() {
  int i, j, n, out, hit, score;
  char stack[50][100][10];

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    out = 0;
    for (j = 0; j < 100; j++) {
      if (out == 3)
        break;
      scanf("%s", stack[i][j]);
      if (strcmp(stack[i][j], "OUT")==0)out++;
    }
  }

  for (i = 0; i < n; i++) {
    score = 0;
    hit = 0;
    for (j = 0; j < 100; j++) {
      if (strcmp(stack[i][j], "HOMERUN")==0) {
        score++;
        score += hit;
        hit = 0;
      }
      if (strcmp(stack[i][j], "HIT")==0)
        hit++;
      if (hit == 4) {
        hit = 3;
        score++;
      }
    }
    printf("%d\n", score);
  }

  return 0;
}

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

int main() {
	int n;
	cin >> n;
	while (n--) {
		int out_count = 0;
		int runner_count = 0;
		int score = 0;
		while (true) {
			string event;
			cin >> event;
			if (event == "HIT") {
				if (runner_count != 3) {
					++runner_count;
				}
				else {
					++score;
				}
			}
			else if (event == "HOMERUN") {
				score += runner_count + 1;
				runner_count = 0;
			}
			else { // event == "OUT"
				if (++out_count == 3) {
					cout << score << endl;
					break;
				}
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  int ing,ans[n];
  string str;
  memset(ans,0,sizeof(ans));
  for(int i=0;i<n;i++){
    int out=0;
    int hit=0;
    while(1){
      if(out==3)break;
      cin>>str;
      if(str=="HIT"){
	hit++;
	if(hit==4)ans[i]+=1;
	if(hit>3)hit=3;
      }
      else if(str=="OUT"){
	out++;
      }
      else if(str=="HOMERUN"){
	ans[i]+=1+hit;
	hit=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
	int n,ans;
	int out;
	bool runner[3];
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		ans=0;
		out=0;
		memset(runner,false,sizeof(runner));
		while(out<3){
			cin>>s;
			if(s=="OUT")out++;
			if(s=="HIT"){
				if(runner[2]){
					ans++;
					runner[2]=false;
				}
				if(runner[1]){
					runner[2]=true;
					runner[1]=false;
				}
				if(runner[0])runner[1]=true;
				runner[0]=true;
			}
			if(s=="HOMERUN"){
				for(int i=0;i<3;i++){
					if(runner[i]){
						ans++;
						runner[i]=false;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}

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;
	 if(E=="HIT"){
	  if(T){point++;}
	  T=S;S=F;F=true;
	 }else if(E=="HOMERUN"){
	  point++;
	  if(F){point++;F=false;}
	  if(S){point++;S=false;}
	  if(T){point++;T=false;}
	 }else{
	  out++;
	 }
	}
	cout<<point<<endl;
	//???????????§
	}
	
	return 0;
}

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

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

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 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;

int n;
int count_HIT=0, count_OUT=0;
int Point[2] = {0,0};
int i=0;
string S;

void solve()
{
	while (count_OUT <3)
	{
		cin >> S;
		if (S == "HIT")
		{
			count_HIT++;
			if (count_HIT == 4)
			{
				Point[i]++;
				
				count_HIT -- ;
			}
		}
		else if (S == "HOMERUN")
		{
			Point[i] += count_HIT + 1;
			
			count_HIT = 0;
		}
		else count_OUT++;
	}
	count_OUT = 0; count_HIT = 0;
	i ^= 1;
	cout << Point[0] << endl
		<< Point[1] << endl;
	return;
}

int main()
{
	cin >> n;
	REP(j, n)
	{
		solve();
	}

	

	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 <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
	int n,ans;
	int out;
	bool runner[3];
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		ans=0;
		out=0;
		memset(runner,false,sizeof(runner));
		while(out<3){
			cin>>s;
			if(s=="OUT")out++;
			if(s=="HIT"){
				if(runner[2])ans++;
				if(runner[1])runner[2]=true;
				if(runner[0])runner[1]=true;
				runner[0]=true;
			}
			if(s=="HOMERUN"){
				for(int i=0;i<3;i++){
					if(runner[i]){
						ans++;
						runner[i]=false;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}