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 <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;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        int outCount=0, base=0, point=0;
        while(outCount < 3){
            char event[8]={0};
            scanf("%s",event);
            if(event[1] == 'I'){
                base <<= 1;
                base |= 1;
                if(base & 8){
                    point++;
                    base ^= 8;
                }
            }else if(event[0] == 'H'){
                int runnerCnt=1;
                while(base > 0){
                    if(base & 1)runnerCnt++;
                    base >>= 1;
                }
                point += runnerCnt;
            }else{
                outCount++;
            }
        }
        printf("%d\n",point);
    }
    return 0;
}