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 <array>

class Baseball{
	private:
	int out_count;
	std::array<int, 4> runner; 	//first second third home
								//runner:1 no:0 home:point
	
	public:
	Baseball(){
		out_count = 0;
		for(int i=0; i<4; ++i)
			runner[i] = 0;
	}
	
	void ining(){
		while(out_count != 3){
			std::string str;
			std::cin >> str;
		
			if(str == "HIT") hit();
			else if(str == "OUT") out();
			else if(str == "HOMERUN") homerun();
		}
		
		std::cout << runner[3] << std::endl;
		return;
	}
	
	void hit(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 0){
				runner[i] = 1;
				return;
			}
			if(i == 3)
				++runner[i];
		}
	}
	
	void out(){
		++out_count;
	}
	
	void homerun(){
		for(int i=0; i<4; ++i){
			if(runner[i] == 1){
				++runner[3];
				runner[i] = 0;
			}
		}
		++runner[3];
	}
};

int main(){
	int n;
	std::cin >> n;
	
	for(int k=0; k<n; ++k){
		Baseball game;
		game.ining();
	}

	return 0;
}

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

int main(void)
{
	int i;
	int n;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		int out = 0;
		int hit = 0;
		int point = 0;
		while (1){
			char str[16];
			scanf("%s", str);
			
			if (strcmp(str, "HIT") == 0){
				hit++;
				if (hit > 3){
					hit--;
					point++;
				}
			}
			if (strcmp(str, "HOMERUN") == 0){
				point += hit + 1;
				hit = 0;
			}
			if (strcmp(str, "OUT") == 0){
				out++;
			}
			if (out >= 3) break;
		}
		printf("%d\n", point);
	}
	return (0);
}

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

class Baseball{
    private:
        std::queue<int> runner;
        int out_count;
        int score;
        
    public:
        void Baseball::initRunner(){
            while(runner.empty() != true){
                runner.pop();
            }
            for(int i = 0; i < 3; ++i){
                runner.push(0);
            }
        }
        
        Baseball(){
            out_count = 0;
            score = 0;
            initRunner();
        }
        
        ~Baseball(){}
        
        void Baseball::hit(){
            if(runner.front() == 1) ++score;
            runner.pop();
            runner.push(1);
        }
        
        void Baseball::homerun(){
            do{
                if(runner.front() == 1) ++score;
                runner.pop();
            } while (runner.empty() != true);
            ++score;
            initRunner();
        }
        
        int Baseball::getScore(){
            std::string str;
            while(out_count != 3){
                std::cin >> str;
                if(str == "HIT") hit();
                if(str == "HOMERUN") homerun();
                if(str == "OUT") ++out_count;
            }
            return score;
        }
};

int main(void){
    int N;
    std::cin >> N;
    for(int i = 0; i < N; ++i){
        Baseball baseball;
        std::cout << baseball.getScore() << std::endl;
    }
}

C++: for i in range(int(input())):
    f, s, t, count, point = 0, 0, 0, 0, 0
    while count != 3:
        data = input()
        if data == 'HIT':
            if t == 1:
                point += 1
                t = 0
            if s == 1:
                t = 1
                s = 0
            if f == 1:
                s = 1
            f = 1
        elif data == 'OUT':
            count += 1
        elif data == 'HO' \
                   '' :
            point += f + s + t + 1
            f, s, t = 0, 0, 0
    print(point)

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

using namespace std;

int main(){

	int n;
	cin>>n;
	string str;
	getline(cin,str);
	for(int i = 0; i < n; i++){
		int out=0;
		bool runnner[3];
		for(int j = 0; j < 3; j++)
			runnner[j]=false;
		int score=0;

		int sit=0;
		while(1){
			getline(cin,str);
			if(str=="HIT"){
				if(sit==0)
					sit=1;
				else if(sit==1){
					sit=3;
				}
				else if(sit==2)
					sit=5;
				else if(sit==4){
					sit=1;
					score++;
				}
				else if(sit==3)
					sit=7;
				else if(sit==5){
					sit=3;
					score++;
				}
				else if(sit==6){
					sit=5;
					score++;
				}
				else if(sit==7){
					sit=7;
					score++;
				}
			}
			else if(str=="OUT"){
				out++;
				if(out==3)
					break;
			}
			else{
				score++;
				if(sit==1){
					score++;
				}
				else if(sit==2)
					score+=1;
				else if(sit==4)
					score+=1;
				else if(sit==3)
					score+=2;
				else if(sit==5)
					score+=2;
				else if(sit==6)
					score+=2;
				else if(sit==7){
					score+=3;
				}
				sit=0;
			}
		}
		cout<<score<<endl;
	}

	return 0;
}

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

int main(){
	int n,score=0,out=0,ining=0,base=0;
	char s[8];
	scanf("%d",&n);
	while(ining!=n){
		scanf("%s",s);
		if(strcmp(s,"HIT")==0){	
			base++;
		}
		else if(strcmp(s,"HOMERUN")==0){
			score+=base+1;
			base=0;
		}
		else if(strcmp(s,"OUT")==0){
			out++;
		}
		if(base==4){
			score++;
			base=3;
		}
		if(out==3){
			ining++;
			printf("%d\n",score);
			score=0;
			out=0;
			base=0;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main(void)
{
  int n,o,p;
  char s[10],b[3];
  scanf("%d",&n);
  while(n--){
    o=p=0;
    while(o!=3){
      scanf("%s",s);
      if(!strcmp(s,"HIT")){
	if(b[2])b[2]=0,p++;
	if(b[1])b[2]=1,b[1]=0;
	if(b[0])b[1]=1;
	b[0]=1;
      }
      if(!strcmp(s,"OUT")){
	o++;
      }
      if(!strcmp(s,"HOMERUN")){
	p+=b[0]+b[1]+b[2]+1;
	memset(b,0,sizeof(b));
      }
    }
    memset(b,0,sizeof(b));
    printf("%d\n",p);
  }
  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 = 0;
			}
		}
		if (S == "HOMERUN")
		{
			Point[i] = count_HIT + 1;
			count_HIT = 0;
		}
		if (S == "OUT")count_OUT++;
	}
	count_OUT = 0; count_HIT = 0;
	i ^= 1;
	n++;
	return;
}

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

	cout << Point[0] << endl
		<< Point[1] << endl;

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int n;
  cin >> n;
  for(int i =0; i < n; i++){
    int base = 0;
    int p = 0;
    for(int out = 0; out < 3;){
      string str;
      cin >> str;
      if(str == "HIT"){
	base++;
      }else if(str == "OUT"){
	out++;
      }else{
	p += base + 1;
	base = 0;
      }
    }
    p += max(0,base - 3);
    cout << p << endl;
  }
}

C++: #include<stdio.h>

main(){
	int c,y,t,o,p;
	char a[9];
	scanf("%d",&c);
	for(y=0;;y++){
		t=o=p=0;
		while(~scanf("%s",&a)||exit(1)){
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}
}