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<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;

int main(){

  int n,ten=0,rui=0,j,i;
  char str[2000];

  scanf("%d",&n);

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

      scanf("%s",str);

      if(strcmp(str,"HIT")==0){
	rui++;
      }
      else if(strcmp(str,"HOMERUN")==0){
	ten+=1+rui;
	rui=0;
      }
      else {
	j++;
      }
      if(rui==4){
	ten++;
	rui=3;
      }
    }
    printf("%d\n",ten);
    ten=0;
    rui=0;
  }

  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
 
int main()
{
    string res;
    int n, cnt = 0, cntH = 0, point = 0;
 
    cin >> n;
    for (int i = 0; i < n;) {
	cin >> res;
     
	if (res == "OUT") {
	    cnt++;
	    if (cnt == 3) {
		i++;
		cnt = 0;
		cout << point << endl;
		point = 0;
		cntH = 0;
	    }
	} else if (res == "HIT") {
	    cntH++;
	    if (cntH == 4) {
		point++; cntH--;
	    }
	} else {
	    point += cntH+1;
	    cntH = 0;
	}
    }
    return 0;
}

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

using namespace std;

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		int count = 3;
		int digit = 0;
		int score = 0;
		while(count)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				digit <<= 1;
				if(digit >= 8)
				{
					++score;
					digit -= 8;
				}
				++digit;
			}
			else if(str == "HOMERUN")
			{
				++score;
				for(int i = 0; i < 3; ++i)
				{
					if(digit & 1)
					{
						++score;
					}
					digit >>= 1;
				}
			}
			else if(str == "OUT")
			{
				--count;
			}
		}
		cout << score << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int Baseball()
{
    const u_int num_of_event = 100;
    u_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 <string>
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;
}

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

int n;
std::string s;
int cnt, pnt;
std::deque<bool> deq;

int main()
{
	std::cin >> n;

	while( std::cin >> s )
	{
		if( s == "HIT" )
		{
			deq.push_back( true );
			
			if( deq.size() > 3 )
			{
				deq.pop_back();
				++pnt;
			}
		}
		else if( s == "HOMERUN" )
		{
			pnt += deq.size() + 1;
			deq.clear();
		}
		else
			++cnt;

		if( cnt == 3 )
		{
			std::cout << pnt << std::endl;
			cnt = pnt = 0;
			deq.clear();
		}
	}

	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int n;
  cin >> n;
  string s;
  int stp = 0, out = 0, run = 0, ans = 0;

  while(stp < n * 3){
    cin >> s;
    if(s == "OUT"){
      out++;
      stp++;
    }
    else if(s == "HIT"){
      if(run == 3) ans++;
      else run++;
    }
    else{
      ans += run + 1;
      run = 0;
    }
    if(out == 3){
      cout << ans << endl;
      out = 0;
      run = 0;
      ans = 0;
    }
  }
}

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

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

C++: #include<stdio.h>

int main(void){

	int i,j,k,q,p,inning,point,kazu[20];
	char eve[10];
	
		point=0;
		j=0;
		k=0;
		q=0;
		p=0;	
	
		scanf("%d",&inning);
		
		for(k=0;k<inning;k++){
		
			point=0;
			j=0;
			q=0;
			p=0;
			
		while(q<3){
		
			for(j=0;j<10;j++){
				eve[j]=0;
			}
			
			scanf("%s",eve);
			
			if(eve[0]=='O'){
				if(eve[1]=='U'){
					if(eve[2]=='T'){
						q++;
					}
				}		
			}
			if(eve[0]=='H'){
				if(eve[1]=='I'){
					if(eve[2]=='T'){
						p++;
						if(p>=4){
							point++;
							p--;
						}
					}
				}
			}		
			
			if(eve[0]=='H'){
				if(eve[1]=='O'){
					if(eve[2]=='M'){
						if(eve[3]=='E'){
							if(eve[4]=='R'){
								if(eve[5]=='U'){
									if(eve[6]=='N'){
										point=point+p+1;
										p=0;
									}
								}
							}
						}		
					}
				}
			}
		}		
		kazu[k]=point;
	}
	for(k=0;k<inning;k++){
		printf("%d\n",kazu[k]);
	}
	return 0;
}

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

using namespace std;

int main(){
	string result[3]={"HIT", "HOMERUN" , "OUT"};
	string eventlist;
	int inning,run;
	int count = 0;
	int score;
	while(cin >> inning){
		for(int i=0;i<inning;i++){
			run = 0; score = 0;
			for(count=0;count < 3;){
				cin >> eventlist;
//				cout << eventlist << endl;
				if(eventlist == result[0]){
					score += (run/4);
					run = (2 * run + 1) % 8;
//					cout << run << "H" << score << endl;
				}
				else if(eventlist == result[1]){
					for(int j = 0;j < 3;j++){
						score += run % 2;
						run = run /2;
					}
					run = 0;
					score++;
//					cout << " " << score << endl;
				}
				else{
					count++;
//					cout << "o" << count << endl;
				}
			}
			cout << score << endl;
		}
	}
}