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 <string>
#include <iostream>
#include <map>

class Baseball{
    private:
        int score;
        int out;
        int runner;
        int inning;

    public:
        Baseball(); //コンストラクタ
        int getScore() { return score; }
        int addScore(int score) { score += score; }
        int getInning() { return inning; }
        bool addOut(); //アウトを加える，チェンジならtrue
        void moveOnRunner(); //ヒット時にランナーを進塁させる
        void slamHomeRun(); //ホームランを打ったとき
        void changeInning(); //イニングを変える，スコア, ランナーも0に戻す
};
Baseball::Baseball(){
    score = 0;
    out = 0;
    runner = 0;
    inning = 1;
}

bool Baseball::addOut(){
    out = (out + 1) % 3;
    return out == 0 ? true : false;
}

void Baseball::moveOnRunner(){
    if(runner < 3){
        runner++;
    } else if(runner == 3){
        runner = 3;
        score += 1;
    }
}

void Baseball::slamHomeRun(){
    score += (runner + 1);
    runner = 0;
}

void Baseball::changeInning(){
    score = 0;
    runner = 0;
    inning += 1;
}

int main(){
    Baseball b;
    int totalInning = 0;
    bool change_flag = false;
    std :: string event;
    std :: map<std :: string, int> map;

    map["HIT"] = 1;
    map["HOMERUN"] = 2;
    map["OUT"] = 3;

    std :: cin >> totalInning;
    std :: getline(std :: cin, event);
    while(b.getInning() <= totalInning){
        std :: getline(std :: cin, event);
        switch(map[event]){
            case 1:
                b.moveOnRunner();
                break;
            case 2:
                b.slamHomeRun();
                break;
            case 3:
                change_flag = b.addOut();
                break;
            default:
                break;
        }
        if(change_flag) {
            std :: cout << b.getScore() << std :: endl;
            b.changeInning();
            change_flag = false;
        }
    }
}

C++: #include <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

int n, point, out;
bool b[5];
string s;

int main(){
	cin >> n;
	REP(k, n){
		while (true){
			cin >> s;
			if (s == "HIT"){
				if (b[3]) { point++; b[3] = 0; }
				if (b[2]) { b[3] = 1; b[2] = 0; }
				if (b[1]) { b[2] = 1; }
				b[1] = 1;
			}
			else if (s == "OUT") {
				out++;
				if (out == 3) { cout << point << endl; break; }
			}
			else if (s == "HOMERUN"){
				if (b[1]) point++;
				if (b[2]) point++;
				if (b[3]) point++;
				point++;
				b[1] = b[2] = b[3] = 0;
			}
		}
		point = 0;
		out = 0;
		b[1] = b[2] = b[3] = 0;
	}
}

C++: b,o,s;main(a){for(scanf("%d");~scanf("%s",&a);)
        {
                if(a%3){
                        if(a&1,++o){
                                if(o%3){
                                        b=!printf("%d\n",s+b>3?b-3:0),s=0;
                                }
                        }
                        else{
                                b++;
                        }
                }
                else{
                        s+=b,b=0;
                }
        }
}

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

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;

    while(--n >= 0){
        int ret = 0;
        int out = 0;
        bool first = false;
        bool second = false;
        bool third = false;

        for(;;){
            string s;
            cin >> s;
            if(s == "HIT"){
                if(third)
                    ++ ret;
                third = second;
                second = first;
                first = true;
            }else if(s == "HOMERUN"){
                if(first)
                    ++ ret;
                if(second)
                    ++ ret;
                if(third)
                    ++ ret;
                ++ ret;
                first = second = third = false;
            }else{
                ++ out;
                if(out == 3)
                    break;
            }
        }
        cout << ret << endl;
    }
}

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

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    vector<int> base(3,0);
    int res=0;
    int out=0;
    while(out!=3){
      string s;
      cin>>s;
      if(s=="HIT"){
	res+=base[2];
	base[2]=base[1];
	base[1]=base[0];
	base[0]=1;
      }
      if(s=="OUT"){
	out++;
      }
      if(s=="HOMERUN"){
	res+=base[0]+base[1]+base[2];
	for(int i=0;i<3;i++) base[i]=0;
      }

    }
    cout<<res<<endl;

  }
  return 0;
}

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

int main() {
  int n,first,second,third,point,out;
  string str;
  while(cin >> n) {
    point = 0;
    out = 0;
    first = 0;
    second = 0;
    third = 0;
    for(int i=0;i<n;i++) {
      cin >> str;
      if(str == "HIT") {
	if(third == 1) {
	  third = 0;
	  point++;
	}
	if(second == 1) {
	  second = 0;
	  third = 1;
	}
	if(first == 1) {
	  second = 1;
	}
	first = 1;
      }
      else if(str == "OUT") {
	out++;
	if(out == 3) break;
      }
      else if(str == "HOMERUN") {
	point += 1 + first + second + third;
	first = 0;
	second = 0;
	third = 0;
      }
    }
    cout << point << endl;
  }
}

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

int main(void){
    using namespace std;
    
    int i,j,k,l;
    int data_set;
    string data;
    int out;
    int field[4];
    int point;
    
    cin>>data_set;
    for(i=0;i<data_set;i++){
        out=0;
        memset(field,0,sizeof(field));
        
        while(out<3){
            cin>>data;
            if(data=="HIT"){
                field[3]+=field[2];
                field[2]=field[1];
                field[1]=field[0];
                field[0]=1;
            }
            else if(data=="HOMERUN"){
                for(j=0;j<3;j++){
                    field[3]+=field[j];
                    field[j]=0;
                }
                field[3]++;
            }
            else if(data=="OUT"){
                out++;
            }
        }
        point=field[3];
        cout<<point<<endl;
    }
    return(0);
}