Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

C++: #include <iostream>
using namespace std;
int main( void )
{
	int n;
	cin >> n;

	int i = 0;

	int point = 0;
	int hit = 0;
	int now = 0;
	while ( i < n )
	{
		string s;
		cin >> s;
		if ( s == "OUT" )
		{
			now++;
		}
		else if ( s == "HIT" )
		{
			if ( hit >= 3 )
				point++;
			hit++;
		}
		else if ( s == "HOMERUN" )
		{
			point += hit + 1;
			hit = 0;
		}

		if ( now >= 3 )
		{
			cout << point << endl;
			now = 0;
			point = 0;
			hit = 0;
			i++;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int i,j,k,n,f1,f2,f3,h1,h2,h3;
	int out,hit,hran,v;
	char s[8];
	cin>>n;
	for(i=0;i<n;i++) {
		out=hit=hran=v=f1=f2=f3=0;
		while(1) {
			cin>>s;
			if(strcmp("HIT",s)==0) {
				h1=h2=h3=0;
				if(f1==0) f1=1,h1=1;
				if(f2==0&&f1==1&&h1==0) f2=1,h2=1;
				if(f3==0&&f2==1&&h2==0) f3=1,h3=1;
				if(f3==1&&h3==0) v++;
			}
			if(strcmp("HOMERUN",s)==0) {
				v+=(f1+f2+f3+1);
				f1=f2=f3=0;
			}
			if(strcmp("OUT",s)==0) {
				out++;
				if(out==3) {out=0;break;}
			}
		}
		cout<<v<<endl;
	}
}

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

int main()
{
	string in;
	bool runner[3];
	int point,out,n;
	int i,j;

	scanf("%d",&n);

	for(i = 0; i < n; i++){
		out = 0;
		point = 0;
		for(j = 0; j < 3; j++){
			runner[j] = false;
		}

		while(out < 3){
			cin >> in;
			if(in == "HIT"){
				if(runner[2]){
					point++;
				}
				else if(runner[1]){
					runner[2] = true;
				}
				else if(runner[0]){
					runner[1] = true;
				}
				else{
					runner[0] = true;
				}
			}
			else if(in == "OUT"){
				out++;
			}
			else if(in == "HOMERUN"){
				for(j = 0; j < 3; j++){
					if(runner[j]){
						runner[j] = false;
						point++;
					}
				}
				point++;
			}
		}
		printf("%d\n",point);
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  while(n--){
    string str;
    int o = 0, p = 0, r=0;
    while(o < 3){
      cin >> str;
      if(str == "HIT"){
	if(r<3) r++;
	else p++;
      }else if(str == "HOMERUN"){
	p += r+1;
	r = 0;
      }else if(str == "OUT"){
	o++;
      }
    }
    cout << p << endl;
  }
  return 0;
}

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

int main(){
    int n, out,tmp, runner, score;
    string str;

    cin >> tmp;
    n = tmp;
    cin.get();
    while (n--){
	out = runner = score = 0;
	while (out!=3){
	    getline(cin, str);
	    if (str == "HIT"){
		runner++;
		if (runner == 4){
		    runner--;
		    score++;
		}
	    }
	    else if (str == "HOMERUN"){
		score += runner += 1;
		runner = 0;
	    } else if (str == "OUT") out++;
	}
	cout << score << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int ining;
	std::cin >> ining;
	std::string s;
	for (int i = 0; i < ining; ++i) {
		int co = 0;
		int ch = 0;
		int c = 0;
		while (std::cin >> s) {
			if (s == "OUT") {
				++co;
			}
			if (co == 3) {
				break;
			}
			if (s == "HIT") {
				++ch;
			}
			if (ch == 4) {
				--ch;
				++c;
			}
			if (s == "HOMERUN") {
				c += ch + 1;
				ch = 0;
			}
		}
		std::cout << c << std::endl;
	}
	}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,base[4],pt,now;
	cin>>n;
	string s;
	while(n-->0){
		pt=0;
		for(int i=0;i<3;i++)
			base[i]=0;
		for(now=3;now>0;){
			getline(cin,s);
			if(s=="HIT"){
				if(base[2]==1)
					pt++;
				for(int i=2;i>0;i--)
					base[i]=base[i-1];
				base[0]=1;
			}
			else if(s=="HOMERUN"){
				for(int i=0;i<3;i++){
					if(base[i]==1)
						pt++;
					base[i]=0;
				}
				pt++;
			}
			else if(s=="OUT"){
				now--;
			}
		}
		cout<<pt<<endl;
	}
	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++;
	hit = 3;
      }
    }
    else if( s == "HOMERUN" ){
      ten = ten + hit + 1;
      hit = 0;
    }
    else{
      out++;
    }
  }
  cout << ten << endl; 
}

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

  return 0;
}

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

int main() {

  int inning;
  char result[50];

  int base[3];
  int out;
  int point;

  int i,j;
  char c;

  scanf("%d",&inning);
  c=getchar();
  
  for(i=0;i<inning;i++) {
    
    for(j=0;j<3;j++) base[j]=0;
    //printf("%d %d %d\n",base[0],base[1],base[2]);
    out=0;
    
    point=0;

    while(1) {

      fgets(result,sizeof(result),stdin);

      result[strlen(result)-1]='\0';

      if(strcmp(result,"OUT")==0) {
	out++;
      }

      if(strcmp(result,"HOMERUN")==0) {
	
	for(j=0;j<3;j++) {
	  if(base[j]==1) point++;
	  base[j]=0;
	}

	point++;
      }

      if(strcmp(result,"HIT")==0) {
	
	if(base[2]==1) point++;

	for(j=0;j<3;j++) {
	  if(base[j]==0) {
	    base[j]=1;
	    break;
	  }
	}
      }
      //printf("%d %d %d %d %d\n",out,point,base[0],base[1],base[2]);
      if(out==3) break;

    }

    printf("%d\n",point);

  }

  return 0;

}

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

class Baseball {
    // 各ビットがそれぞれの塁のランナーの有無を表現する
    std::bitset<4> runners;
    u_int _out, _score;
public:
    Baseball() = default;
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() { ++_out; }
    void change();
    bool is_change() { return _out == 3; }
    u_int score() { return _score; }
};

void Baseball::hit() {
    runners <<=1;   // ランナーを1つずつ進める
    runners.set(0); // 一塁にランナーを置く
    // ホームインしたかどうか
    if (runners.test(3)) {
        ++_score;
        runners.reset(3);
    }
}

void Baseball::homerun() {
    _score += runners.count() + 1;
    runners.reset(); // ランナーをリセット
}

void Baseball::change() {
    _out = _score = 0;
    runners.reset();
}

int main(void) {
    u_int n;
    std::string event;
    Baseball game;

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        do {
            std::cin >> event;
            if ("HIT" == event) {
                game.hit();
            } else if ("HOMERUN" == event) {
                game.homerun();
            } else if ("OUT" == event) {
                game.out();
            }
        } while (!game.is_change());

        std::cout << game.score() << std::endl;
        game.change();
    }

    return 0;
}

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

vector<int> ans;
int main(){
  int n;
  
  cin >> n;
  for(int i=0; i<n; ++i){
    bitset<3> base{0};
    int flag = 0;
    int score = 0;
    string nock;

    while(flag!=3){
    cin >> nock;

    if(nock == "HIT"){
      if(base == 000){
	base = 001;
      }else if(base[2]){
	base = base << 1;
	base |= 001;
	++score;
      }else{
	base = base << 1;
	base |= 001;
      }
    }
    
    if(nock == "OUT"){
      ++flag;
      if(flag == 3){
	ans.push_back(score);
	//cout << "end" << endl;
      }
    }
    if(nock == "HOMERUN"){
      int j;
      j = base.count();
      score += j + 1;
      base = 000;
    }
    }
  }
  for(auto i:ans){
    cout << i << endl;
  }
  return 0;
}