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++: //0103
#include<string.h>
#include<stdio.h>
int main()
{
	int n,op,f,se,t,r;
	char s[16];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		r=0;
		op=0;
		f=0;
		se=0;
		t=0;

		while(op<3){
			scanf("%s",s);
			if(strcmp("OUT",s)==0){
				op++;
			}else if(strcmp("HIT",s)){
				r+=t;
				t=se;
				se=f;
				f++;
			}else{
				r+=(f+se+t+1);
				f=s=t=0;
			}
		}
		printf("%d\n",r-3);
	}
	return 0;
}

C++: #include<stdio.h>

int main(void)
{
  char str[16]={};
  int n;
  int i;
  int score=0;
  int base=0;
  int out=0;

  scanf("%d", &n);

  for(i=0;i<n;i++)
    {
      score=0;
      base=0;
      out=0;
      while(1)
        {
          scanf("%s", str);
          if(str[1]=='I')
            if(base==3)
              score++,base=0;
            else
              base++;
          else if(str[1]=='U')
            if(out==2)
              break;
            else
              out++;
          else if(str[1]=='O')
            score+=base+1,base=0;
        }
      printf("%d\n", score);
    }
  return 0;
}

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

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

using namespace std;

int main() {
	int n;
	int base = 0, out = 0, score = 0;
	cin >> n;
	
	while(1) {
		char str[10];
		if(EOF == scanf("%s", str)) break;
		if(str == "OUT") {
			out++;
			if(out >= 3) {
				cout << score <<endl;
				score = out = base = 0;
				n--;
			}
		} else if(str == "HOMERUN") {
			score += base + 1;
			base = 0;
		} else {
			base++;
			if(base >= 4) {
				score++;
				base--;
			}
		}
	}
	if(n) {
		cout << score << endl;
	}
	return 0;
}

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

int main()
{
	int n,point=0,temp=0,out=0,i=0;
	vector <int>result;
	string a;
	cin >> n;
	while (i<n)
	{
		cin >> a;
		if (a == "HIT")
		{
			if (temp==3)
			{
				point++;
			}
			else
			{
				temp++;
			}
		}
		else if (a == "HOMERUN")
		{
			point = point+temp+1;
			temp = 0;
		}
		else if (a == "OUT")
		{
			out++;
			if (out == 3)
			{
				i++;
				out = 0;
				temp = 0;
				result.push_back(point);
				point = 0;
			}
		}
	}
	for (int j=0; j < n; j++)
	{
		cout << result.at(j) << endl;
	}
	return 0;
}

C++: // 2011/01/05 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

	for(int i=0; i<n; i++){
		int ots = 0;
		int sco = 0;
		int ba1 = 0, ba2 = 0, ba3 = 0;

		while(ots<3){
			string eve;
			cin >> eve;

			if(eve=="HIT"){
				sco += ba3;
				ba3 = ba2;
				ba2 = ba1;
				ba1 = 1;
			}
			else if(eve=="HOMERUN"){
				sco += (ba3+ba2+ba1+1);
				ba3 = ba2 = ba1 = 0;
			}
			else if(eve=="OUT"){
				ots++;
			}
		}

		cout << sco << endl;
	}

	return 0;
}

C++: #include <stdio.h>
int main() {char T[20];int N,pnt,ot,base;scanf("%d",&N); {while (N--) {pnt=ot=base=0;while (1) {scanf("%s",&T);if (T[0]=='O') ot++; else if (T[1]=='O') pnt+=base+1,base=0; else base++,pnt+=((base&4)?1:0),base-=((base==4)?1:0);if (ot==3) {printf("%d\n",pnt);break;}}}} return 0;}

C++: #include <iostream>
#include <string>
int main(){
	int inning;
	std::cin >> inning;
	for (int i = 0; i < inning; i++) {
		int out = 0;
		int runner = 0;
		int score = 0;
		while (out < 3) {
			std::string event;
			std::cin >> event;
			if (event == "HIT") {
				if (runner == 3) {
					score++;
				}
				else runner++;
			}
			if (event == "OUT") {
				out++;
			}
			if (event == "HOMERUN") {
				score += runner + 1;
				runner = 0;
			}
		}
		std::cout << score << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    rep(i,0,n) {
        int outcnt = 0, ans = 0;
        int bit = 0;
        while(1) {
            string s; cin >> s;
            if(s == "OUT") outcnt++;
            if(outcnt >= 3) break;

            if(s == "HIT") {
                if(bit >> 2 & 1) ans++;
                bit = (bit << 1 | 1) & ((1 << 3) - 1);
            }
            else if(s == "HOMERUN") {
                ans += (__builtin_popcount(bit) + 1);
                bit = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int main(int argc, char **argv)
{
	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>
class Baseball{
private:
    int score,out,runner,inning;
public:
    Baseball();
    ~Baseball()=default;
    void checkEvent(std::string event);
    void hit();
    void homerun();
    void countOut();
    int getInning();
};

Baseball::Baseball(){
    score=0,out=0,runner=0,inning=0;
}

void Baseball::checkEvent(std::string event){
    if(event=="HIT"){
        this->hit();
    }
    else if(event=="OUT"){
        this->countOut();
    }
    else if(event=="HOMERUN"){
        this->homerun();
    }
}

void Baseball::hit(){
    runner<3?++runner:++score;
}
	
void Baseball::countOut(){
    if(out<2){
        ++out;
    }
    else{
	std::cout << score << std::endl;
	runner=0,out=0,score=0;++inning;
    }
}
	
void Baseball::homerun(){
    score+=runner+1;
    runner=0;
}	

int Baseball::getInning(){
    return inning;
}

int main() {
    Baseball game;
    int num;
    std::cin >> num;
    while(game.getInning()<num){
        std::string event;
	std::cin >> event;
	game.checkEvent(event);
    }
    return 0;
}