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>
#include <string>
using namespace std;

int main()
{
	int n,inning=0;
	int p[40] = {0};
	string ivent;

	cin >> n ;
	while (1)
	{
		int r=0, o=3;                        //r = ???????????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p[inning]++;
				}
			}

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)                       //?????? = ???????????? + ????????????(1???)
				{
					p[inning] += 4;
				}
				else
				{
					p[inning] += r + 1;
				}
				r = 0;                            //??????????????????????????????
			}
			else if (ivent=="OUT")
			{
				o--;
			}
		}
                      
		inning++;
		if (n == inning) break;

	}

	for (int i = 0; i < n; i++)
	{
		cout << p[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
int main(void){
int datasets,i,hit=0,out,remain=0;
std::string input;
std::cin >> datasets;
for(i=0;i<datasets;++i){
	out=0;
	while(out<3){
		std::cin >> input;
		if(input=="HIT"){
			++hit;
			++remain;
		}
		if(input=="HOMERUN"){
			++hit;
			remain=0;
		}
		if(input=="OUT") ++out;
	}
	if(remain>3) remain=3;
	std::cout << hit-remain;
	hit=0;
	remain=0;
}
return 0;
}

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

int Baseball()
{
    const u_int num_of_event = 100;
    int num_of_runner = 0, num_of_out = 0, point = 0;
    std::string event;
    
    for(u_int i = 0; i < num_of_event; ++i){
        std::cin >> event;
        if(event == "HIT"){
            if(num_of_runner == 3)
                ++point;
            else
                ++num_of_runner;
        }
        else if(event == "HOMERUN"){
            point += 1 + num_of_runner;
            num_of_runner = 0;
        }
        else{
            ++num_of_out;
            if(num_of_out == 3)
                break;
        }
    }
    
    return point;
}

int main()
{
    u_int num_of_inning;
    std::cin >> num_of_inning;
    
    for(u_int i = 0; i < num_of_inning; ++i){
        std::cout << Baseball() << std::endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int score=0;
		int runner=0;
		for(int j=0;j<3;){
			string s;
			cin>>s;
			if(s=="HIT"){
				if(runner==3)
					score++;
				else
					runner++;
			}
			else if(s=="HOMERUN"){
				score+=runner+1;
				runner=0;
			}
			else
				j++;
		}
		cout<<score<<endl;
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  cin>>n;
  rep(i,n){
    int out=0,point=0;
    int run[3]={};
    string s;
    int F=0,S=0,T=0;
    while(out!=3){
      cin>>s;
      if(s=="OUT")out++;
      else if(s=="HOMERUN"){
        rep(i,3){
          point+=run[i];
          run[i]=0;
        }
        point++;
      }else{
        if(run[2]==1)point++;
        for(int i=2;i>0;i--)run[i]=run[i-1];
        run[0]=1;
      }
    }
    cout<<point<<endl;
  }
  return 0;
}

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

int main()
{
	int n;
	string s;
	cin >> n;
	while (n--) {
		int res = 0, O = 0;
		vector<int> r(3);
		while (true) {
			cin >> s;
			if (s == "HIT") {
				res += r[2];
				r[2] = r[1];
				r[1] = r[0];
				r[0] = 1;
			}
			else if (s == "HOMERUN") {
				res += r[0] + r[1] + r[2] + 1;
				r[0] = r[1] = r[2] = 0;
			}
			else {
				O++;
				if (O >= 3) {
					break;
				}
			}
		}
		cout << res << endl;
	}
	return 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[50] = {};
	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){
				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;
				}
				inning++;
			}
		}
		i++;
	}

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

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

using namespace std;

int main() {
  int n, first = 0, second = 0, third = 0, out = 0, point = 0;
  cin >> n;
  for (int inning = 0; inning < n;) {
    string event;
    cin >> event;
    if (event == "HIT") {
      if (third) point++;
      third = second;
      second = first;
      first = 1;
    } else if (event == "HOMERUN") {
      point += first + second + third + 1;
      first = second = third = 0;
    } else if (event == "OUT") {
      out++;
      if (out == 3) {
        inning++;
        cout << point << endl;
        first = second = third = out = point = 0;
      }
    }
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main()
{
	int n, p = 0, o, t, i, j;
	string e;
	bool b[3] = {false};
	cin >> n;
	for (i = 0; i < n; i++)
	{
		o = p = 0;
		b[0] = b[1] = b[2] = false;
		while (o < 3)
		{
			cin >> e;
			if (e == "HIT")
			{
				if (b[2] == true)
				{
					p++;
					b[2] = false;
				}
				if (b[1] == true)
				{
					b[1] = false;
					b[2] = true;
				}
				if (b[0] == true)
				{
					b[0] = false;
					b[1] = true;
				}
				b[0] = true;
			}
			if (e == "HOMERUN")
			{
				for (j = t = 0; j < 3; j++)
				{
					if (b[j])
					{
						b[j] = false;
						t++;
					}
				}
				p += t+1;
			}
			if (e == "OUT")
				o++;
		}
		cout << p << endl;
	}
}