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;
	string str;
	cin >> n;
	while(n--){
		int ans = 0, out = 0, per = 0;
		while(1){
			cin >> str;
			if(str[1] == 'I'){
				per++;
				if(per > 3){per--;ans++;}
			}
			if(str[1] == 'O'){
				ans += per + 1;
				per = 0;
			}
			if(str[1] == 'U' && ++out == 3)break;
			//cout << per << ans << endl;
		}
		cout << ans << endl;
	}
}

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

int main(void){
	int n;
	cin>>n;
	while(n--){
		string s;
		valarray<int> h(3);
		int o=0;
		int sc=0;
		h=0;
		while(o!=3){
			cin>>s;
			if(s[0]=='O')o++;
			else if(s[1]=='I'){
				sc+=h[2];
				h=h.shift(1);
				h[0]=1;
			}else{
				sc+=1+h.sum();
				h=0;
			}
		}
		cout<<sc<<endl;
	}
	return 0;
}

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]++;
                                        r=3;
				}
			}

			else if (ivent=="HORMRUN")
			{
				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.h>
using namespace std;

int main(){
	char input[10];
	int loc = 0, all = 0;
	int point = 0;
	int out = 3;
	int e;

	cin >> e;
	while(e != 0){
		cin >> input;
		if( strcmp(input, "HIT") == 0 ){
			loc++;
			if(loc > 3){
				loc--;
				point++;
			}
				
		}else if( strcmp(input, "OUT") == 0){
			out--;
			if(out == 0){
				out = 3;
				e--;
				loc = 0;
				cout << point << endl;
				point = 0;
			}
		}else if( strcmp(input, "HOMERUN") == 0){
			point++;
			point += loc;
			loc = 0;
		}
	}

}

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

int main()
{
	int n;
	string ivent;

	cin >> n ;
	while (n--)
	{
		int r=0, p=0, o=3;
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)
				{
					p++;
				}
			}

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)
				{
					p += 4;
				}
				else
				{
					p += r + 1;
				}
				r = 0;
			}
			else
			{
				o--;
			}
		}

		cout << p << endl;

	}


	return 0;
}

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

int n;
string eventType;
int point;
int outCount;
bool first, second, third;

void hit()
{
	point += third;
	third = second;
	second = first;
	first = true;
}
void homerun()
{
	point++;
	point += first;
	point += second;
	point += third;
	first = false;
	second = false;
	third = false;
}
void out()
{
	outCount++;
}

int main()
{
	cin >> n;
	while (n--)
	{
		point = 0;
		outCount = 0;
		first = false;
		second = false;
		third = false;

		while (true)
		{
			cin >> eventType;
			if (eventType == "HIT") hit();
			if (eventType == "HOMERUN") homerun();
			if (eventType == "OUT") out();

			if (outCount == 3)
			{
				cout << point << endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){
	int n; cin >> n ;
	int scoreA=0 ; int scoreB=0 ;
	for(int i=0;i<n;i++){
		int base=0; int out=0;string str; int score=0;
		while(1){
			cin >> str ;
			for(int i=0;str[i];i++) str[i]=toupper(str[i]);
			if(str=="OUT") out++;
			else if(str=="HIT") base++;
			else if(str=="HOMERUN") do{score+=++base; base=0;}while(0);
			if(out>=3) break;
			if(base>=4) do{base=3;score++;}while(0);
			};
		if(i%2==0) scoreA+=score; else scoreB+=score;
	};
	cout << scoreA << '\n' << scoreB << '\n' ;
}

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

int point;
int rui;
int oc;

void hit(){
  rui++;
  if(rui>3){
    point++;
    rui=3;
  }
}
void out(){
  oc++;
}

void home(){
  point+=1;
  point+=rui;
  rui=0;
}

int main(){
  int i,n;
  string event;
  point=0;
  rui=0;
  oc=0;

  cin >> n;
  for(i=0;i<n;i++){

    while(1){
      if(oc==3){
	rui=0;
	oc=0;
	break;
}
      cin >> event;
      if(event == "HIT"){
	hit();
      }else if(event == "OUT"){
	out();
      }else if(event == "HOMERUN"){
	home();
      }
    }
    cout << point << endl;
    point=0;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int score=0;
		int a=0,b=0,c=0;
		for(int out=0;out<3;)
		{
			string s;cin>>s;
			if(s=="HIT")
			{
				score+=c;
				c=b;
				b=a;
				a=1;
			}
			else if(s=="HOMERUN")
			{
				score+=a+b+c+1;
				a=b=c=0;
			}
			else
			{
				out++;
			}
		}
		cout<<score<<endl;
		
	}
}

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>
using namespace std;
int main(void){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int out=0,base=0,point=0;
		while(out<3){
			string event;
			cin >> event;
			if(event == "OUT"){
				out++;
			}else if(event == "HIT"){
				if(base == 3){
					point++;
				}else{
					base++;
				}
			}else{
				point += base + 1;
				base = 0;
			}
		}
		cout << point << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  while(n--){
    int runner = 0;
    int out = 0;
    int point = 0;
    
    while(out<3) {
      string s;
      cin >> s;
      
      if(s=="HIT"){
	runner++;
      }

      else if (s=="OUT"){
	out++;
      }

      else if (s=="HOMERUN"){
	point+=runner+1;
	runner = 0;
      }
      
      if(runner == 4) {
	point++;
	runner = 3;
      }
      
    }
    cout << point << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		int out = 0;
		int num_runner = 0;
		int points = 0;

		while(true){
#if INPUT_FROM_FILE
			ifs >> buf;
#else
			std::cin >> buf;
#endif
			if(buf == "HIT"){
				if(num_runner == 3){
					points++;
				}
				else{
					num_runner++;
				}
			}
			else if(buf == "HOMERUN"){
				points += num_runner + 1;
				num_runner = 0;
			}
			else{
				out++;
				if(out == 3){
					std::cout << points << std::endl;
					break;
				}
			}
		}
	}

#if INPUT_FROM_FILE
		//fclose(fp);
#endif
	return 0;
}