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>
#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 <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n,i=0,out=0,score=0;
	bool fir=0,sec=0,thi=0;
	cin>>n;
	while(1){
		string s;
		cin>>s;
		if(s=="HIT"){
			if(thi) score++;
			thi=sec; sec=fir; fir=1;
		}if(s=="OUT"){
			out++;
			if(out==3){
				i++; o(score);
				if(i==n) break;
				fir=sec=thi=0;
				out=0; score=0;
				continue;
			}
		}if(s=="HOMERUN"){
			score++;
			if(fir) score++;
			if(sec) score++;
			if(thi) score++;
			fir=sec=thi=0;
		}
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;

int n;
int count_HIT=0, count_OUT=0;
int Point[2] = {0,0};
int i=0;
string S;

void solve()
{
	while (count_OUT <3)
	{
		cin >> S;
		if (S == "HIT"){
			count_HIT++;
			if (count_HIT == 4)
			{
				Point[i]++;
				
				count_HIT = 0;
			}
		}
		else if (S == "HOMERUN")
		{
			Point[i] += count_HIT + 1;
			
			count_HIT = 0;
		}
		else count_OUT++;
	}
	count_OUT = 0; count_HIT = 0;
	i ^= 1;
	return;
}

int main()
{
	cin >> n;
	REP(j, n)
	{
		solve();
	}

	cout << Point[0] << endl
		<< Point[1] << endl;

	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n;
	cin>>n;
	REP(i,n){
		int b[3]={};
		int score=0;
		int out=0;
		while(1){
			string s;
			cin>>s;
			if(s=="HIT"){
				score+=b[2];
				for(int j=2;j>0;j--){
					b[j]=b[j-1];
				}
				b[0]=1;
			}else if(s=="HOMERUN"){
				REP(j,3){
					score+=b[j];
					b[j]=0;
				}
				score++;
			}else if(s=="OUT"){
				out++;
				if(out==3){
					goto end;
				}
			}
		}
end:
		cout<<score<<endl;
	}
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

int main() {
	int N; cin >> N;
	while (N--) {
		int score = 0;
		int out = 0;
		int run = 0;
		while (out <= 2) {
			string st; cin >> st;
			if (st == "OUT")out++;
			else if (st == "HIT") {
				run++;
				if (run == 4) {
					run = 3;
					score++;
				}
			}
			else {
				score += 1 + run;
				run = 0;
			}
		}
		cout << score << endl;
	}
	return 0;
}

C++: #include <iostream>

class baseball{
	private : 
	bool firstRunner; //first runnner flag
	bool secondRunner; //second runnner flag
	bool thirdRunner; //third runnner flag

	int score; //inning score
	int outCount; //number of out count 

	public :  
	baseball();

	void doHit();
	void doHomerun();
	void doOut();

	int getOutCount();
	void showScore();
};

baseball::baseball(){
	firstRunner = false; 
	secondRunner = false;
	thirdRunner = false;

	score = 0;
	outCount = 0; 
}

void baseball::doHit() {
	//advance to the next base
	if(thirdRunner == true){
		++score;
		thirdRunner = false;
	}
	if(secondRunner == true){
		thirdRunner = true;
		secondRunner = false;
	}
	if(firstRunner == true){
		secondRunner = true;
	}
	firstRunner = true;
}

void baseball::doHomerun(){
	//advance to the next base
	if(thirdRunner == true){
		++score;
		thirdRunner = false;
	}
	if(secondRunner == true){
		++score;
		secondRunner = false;
	}
	if(firstRunner == true){
		++score;
		firstRunner = false;
	}
	++score;
}

void baseball::doOut(){
	//add out count
	++outCount;
}

int baseball::getOutCount(){
	return outCount;
}

void baseball::showScore(){
	std::cout << score << std::endl;
}


int main(void){
	u_int n = 0; //number of data set
	std::cin >> n; //input number of data set

	baseball game[n]; //make n baseball class

	for(size_t i = 0; i < n; ++i){
		while(game[i].getOutCount() < 3){
			std::string str;
			std::cin >> str; //input event

			if(str == "HIT"){ //judge event
				game[i].doHit();
			}else if(str == "HOMERUN"){
				game[i].doHomerun();
			}else if(str == "OUT"){
				game[i].doOut();
			}else{
				std::cout << "error : wrong strings" << std::endl;
			}
		}
		game[i].showScore(); //output inning score
	}

	return 0;
}

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

int main() {
	
	int N,score,f,s,t,out,i;
	string event;
	
	for(cin>>N,i=0;i<N;++i){
		score=out=f=s=t=0;
		
		while(out!=3){
			cin >> event;
			
			if(event == "OUT")++out;
			else if(event == "HIT"){
				if(t)++score;
				t=s;
				s=f;
				f=1;
			}else if(event == "HOMERUN"){
				if(f)++score;
				if(s)++score;
				if(t)++score;
				++score;
				f=s=t=0;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}