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<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int time;
    cin >> time;
    rep(t,time){
        int base[3], old[3];
        int out = 0, point = 0;
        rep(i,3) base[i] = 0;
        string s;
        while(cin >> s){
            if(s == "HIT"){
                old[0] = base[0];
                old[1] = base[1];
                old[2] = base[2];
                if(old[0]) base[1] = 1;
                if(old[1]) base[2] = 1;
                if(old[2]) point++;
                base[0] = 1;
            }
            if(s == "HOMERUN"){
                point++;
                if(base[0]) point++;
                if(base[1]) point++;
                if(base[2]) point++;
                base[0] = 0;
                base[1] = 0;
                base[2] = 0;
            }
            if(s == "OUT"){
                out++;
                if(out == 3) break;
            }

        }
        cout << point << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  int points[n];
  for(int i=0;i<n;i++){
    bool base[3]={false,false,false};int outs=0;
    string action;int point=0;
    while(outs!=3){
      cin>>action;
      if(action=="HIT"){
        if(base[0]==false)base[0]=true;
        else if(base[1]==false)base[1]=true;
        else if(base[2]==false)base[2]=true;
        else point++;
      }
      else if(action=="HOMERUN"){
        int runner=0;
        for(int k=0;k<3;k++){
          if(base[k]==true)runner++;
        }
        for(int k=0;k<3;k++){
          base[k]=false;
        }
        point=point+runner+1;
      }
      else if(action=="OUT"){
        outs++;
      }
    }
    points[i]=point;
  }
  for(int i=0;i<n;i++){
    cout<<points[i]<<endl;
  }
}

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

//class
class Baseball{
public:
	int firstbase, secondbase, thirdbase;
	int inningNumber, out, score;

	Baseball(int num){
		inningNumber = num;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		out = 0;
		score = 0;
	}

	void playball(){
		for(int i = 0; i < inningNumber; ++i)
			inning();
	}

	void inning(){
		out = 0;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		score = 0;

		while(out != 3){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				hit();
			if(str == "HOMERUN")
				homerun();
			if(str == "OUT")
				out++;
		}

		std::cout << score << std::endl;
	}

	void hit(){
		score += thirdbase;
		thirdbase = secondbase;
		secondbase = firstbase;
		firstbase = 1;
	}

	void homerun(){
		score += thirdbase + secondbase + firstbase + 1;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
	}
};
//main
int main(){
	int n;
	std::cin >> n;
	
	Baseball *baseball = new Baseball(n);
	baseball->playball();
	delete baseball;

	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 = 7;
		int point = 0;
		int stt = 0;
		while (o > 0){
			string s;
			cin >> s;
			if (s.compare("HIT") == 0) {
				if (stt & 4) {
					point++;
				}
				stt = (stt << 1) | 1;
			} else if (s.compare("HOMERUN") == 0) {
				while (stt > 0) {
					point++;
					stt = stt >> 1;
				}
				point++;
			} else if (s.compare("OUT") == 0) {
				o = o >> 1;
			}
		}
		cout << point << endl;
	}
	return 0;
}

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

class Baseball{
	private:
	int out;
	int runner;
	int point;

	public:
	void init();
	int get_out();
	int get_point();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::init(){
	out = 0;
	runner = 0;
	point = 0;
}

int Baseball::get_out(){
	return out;	
}

int Baseball::get_point(){
	return point;
}

void Baseball::event_hit(){
	if(runner == 3){
		++point;
	}else{
		++runner;
	}
}

void Baseball::event_homerun(){
	point += ++runner;
}

void Baseball::event_out(){
	++out;
}

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	Baseball base;
	base.init();
	for(int i = 0; i < num; ++i){
		while(base.get_out() < 3){
			std:: cin >> event;

			if(event == "OUT"){
				base.event_out();		
			}else if(event == "HIT"){
				base.event_hit();
			}else if(event == "HOMERUN"){
				base.event_homerun();
			}
		}
		std::cout << base.get_point() << std::endl;
		base.init();
	}
	return 0;
}

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

int main()
{
	int n,count,point,out;
	string s;
	cin >> n;
	while(n--){
		point = count = out = 0;
		while(out < 3){
			cin >> s;
			if(s=="OUT"){
				out++;
			}else if(s=="HIT"){
				count++;
				if(count>3){
					point++;
					count--;
				}
			}else{
				point += count + 1;
				count = 0;
			}
		}
		cout << point << endl;
	}
}

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

using namespace std;

int main()
{
	string str;
	int n;
	int E=0,out=0,score=0,base=0;
	
	cin >> n ;
	for(;;)
	{
		if(E==n)
			break;
		cin >> str ;
		if(str=="OUT")
		{
			out++;
		}
		else if(str=="HIT")
		{
			base++;
			if(base==4)
			{
				score++;
				base--;
			}
		}
		else
		{
			score+=base+1;
			base=0;
		}
		
		if(out==3)
		{
			cout << score << endl;
			out=base=score=0;
			E++;
		}
	}
}

C++: #include<iostream>
#include<vector>
int main(){
	int n,m=0,n2=0,s1=0,s2=0;
	std::cin>>n;
	int o=0;
	std::vector<int> vec(3);
	while(n>m){
		std::string str;
		std::cin>>str;
		if(str=="HIT"&&n2%2==0){
			if(vec[2]==1)s1++,vec[2]=0;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HIT"&&n2%2==1){
			if(vec[2]==1)s2++,vec[2]=0;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HOMERUN"&&n2%2==0){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s1++;
				vec[i]=0;
			}
			s1++;
		}
		if(str=="HOMERUN"&&n2%2==1){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s2++;
				vec[i]=0;
			}
			s2++;
		}
		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,n2++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	std::cout<<s1<<std::endl<<s2<<std::endl;
	return 0;
}

C++: #include <stdio.h>
int main(){
	int run,out,n,score;
	run=out=score=0;
	char* eve;
	scanf("%d",&n);
	while(n--){
		while(out>2){
			scanf("%s",eve);
			if(eve=="HIT"){
				run++;
				if(run>3) score++;
			}
			else if(eve=="OUT") out++;
			else if(eve=="HOMERUN"){
				run=0;
				score++;
			}
		}
		printf("%d\n",score);
		run=out=score=0;
	}
	return 0;
}

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

using namespace std;

void compute(void){

  string s;

  int ten = 0;
  int out = 0;
  int hit = 0;

  while( out != 3 ){

    cin >> s;

    if( s == "HIT"){
      hit++;
      if(hit > 3 ) ten++;
    }
    else if( s == "HOMERUN" ){
      ten += hit + 1;
      hit = 0;
    }
    else{
      out++;
    }
  }
  cout << ten << endl; 
}

int main(void){
  
  int n;  
  cin >> n;
  
  while( n-- ){
    compute();
  }

  return 0;
}