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>
using namespace std;
int main(){
  int n,poi[100],hit,hom,out;
  string exam;
  cin>>n;
  for(int j=0;j<100;j++){
    poi[j]=0;
  }
  for(int i=0;i<n;i++){
    hit=0,hom=0,out=0;
    while(1){
      cin>>exam;
      if(exam=="HIT"){
	hit++;
      }
      if(hit==4){
	hit--;
	poi[i]++;
      }if(exam=="OUT"){
	out++;
      }
      if(out==3){
	break;
      }if(exam=="HOMERUN"){
	poi[i]+=hit;
	poi[i]++;
	hit=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<poi[i]<<endl;
  }
  return 0;
}

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

using namespace std;

class Inning{
private:
  int out;
  int runnner;
  int point;
  int inningN;
public:
  Inning();//コンストラクタ
  void newInning();
  int getInningN(){return inningN;}
  int getPoint(){return point;}
  void doOut(){
    out ++;
    if(out == 3){
      newInning();
    }
  }
  void doHit();
  void doHomerun();
};

void Inning::doHit(){
  if(runnner < 3){
    runnner ++;
  }
  else{
    point ++;
  }
}
void Inning::newInning(){
  out = 0;
  runnner = 0;
  inningN ++;
}

void Inning::doHomerun(){
  point += runnner + 1;
  runnner = 0;
}


//コンストラクタ
Inning::Inning(){
  out = 0;
  runnner = 0;
  point = 0;
  inningN = 0;
}

int main(){
  int N;
  char *str;
  cin >> N;
  Inning inning;

  while(1){
    if(inning.getInningN() == N){
      break;
    }
    cin >> str;
    if(!strcmp(str, "OUT")){
      inning.doOut();
    }
    if(!strcmp(str, "HIT")){
      inning.doHit();
    }
    if(!strcmp(str, "HOMERUN")){
      inning.doHomerun();
    }
  }
  cout << inning.getPoint() << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    string a;
    bool run[3]={false, false, false};
    int out=0, e=0;
    int point[50] = {};
    int j=0;
    int k=0;
    while(cin >> a) {
        if(a=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        j++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }

}

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(){
		point = 0;
		out = 0;
		base = 0;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

	for(int i = 0; i < N; ++i){

		Baseball baseball();

		while(baseball.get_out() != 3){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT")
				baseball.add_out();

		}

		std::cout >> baseball.get_point() >> std::endl;
	}

	return 0;
}

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

int loop;
int HIT,OUT,point;
string stait;
int main(){
  scanf("%d",&loop);
  for(int i=0;i<loop;i++){

int base1=0,base2=0,base3=0;
    point = 0;
    OUT=0;
      while(OUT<3){
	cin>>stait;

	if(stait.substr(0,3)=="HIT"){
	  if(base3==1){base3=0;point++;}
	  if(base2==1){base2=0;base3=1;}
	  if(base1==1){base1=0;base2=1;}
	  base1=1;
	}
	if(stait.substr(0,3)=="OUT"){OUT++;}
	if(stait.substr(0,3)=="HOM"){
	  if(base3==1){base3=0;point++;}
	  if(base2==1){base2=0;point++;}
	  if(base1==1){base1=0;point++;}
	  point++;
	}
      };
    printf("%d\n",point);
  }
}

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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> PL;

ll n, ans = 0, o = 0, b = 0, k = 0;
string s;

int main(){
	cin >> n;
	while (cin >> s&&n){
		if (s == "HIT"){
			k++;
			if (k > 3){
				k--;
				ans++;
			}
		}
		else if (s == "HOMERUN"){
			ans += (k + 1);
			k = 0;
		}
		else{
			o++;
		}
		if (o == 3){
			cout << ans << endl;
			ans = 0;
			o = 0;
			k = 0;
			n--;
		}
	}
}

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

using namespace std;

int main(void){

	int n;
	int run[3+1]={0};
	int out,score;;
	string inp;

	cin>>n;

	for(int i=0;i<n;i++){
		for(int j=0;j<=3;j++) run[j]=0;
		out=0;
		score=0;
		while(1){
			cin>>inp;
			if(inp=="HIT"){
				if(run[3]==1) score++,run[3]=0;
				if(run[2]==1) run[2]=0,run[3]=1;
				if(run[1]==1) run[1]=0,run[2]=1;
				run[1]=1;
			}
			if(inp=="HOMERUN"){
				score++;
				for(int i=1;i<=3;i++){
					if(run[i]==1) score++;
					run[i]=0;
				}
			}
			if(inp=="OUT"){
				out++;
			}
			if(out==3) break;
		}
		cout<<score<<endl;
	}

	return 0;
}