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 <string>

class Baseball {
	private:
		int out;
		int runner;
		int point;
		
	public:
		Baseball(){
			out = 0;
			runner = 0;
			point = 0;
		}
		
		int getOut(){
			return out;
		}
		void addOut(){
			++out;
		}
		
		void hit(){
			++runner;
			if(runner == 4){
				++point;
				--runner;
			}
		}
		void homerun(){
			point += runner + 1;
			runner = 0;
		}
		
		int getRunner(){
			return runner;
		}
		
		int getPoint(){
			return point;
		}
};

int main(){
	int inning;
	std::cin >> inning;
	
	for(int i=0; i<inning; ++i){
		Baseball bs;
		
		while(bs.getOut() < 3){
			std::string str;
			std::cin >> str;
			
			if(str == "HIT"){
				bs.hit();
			}
			if(str == "HOMERUN"){
				bs.homerun();
			}
			if(str == "OUT"){
				bs.addOut();
			}
		}
		std::cout << bs.getPoint() << std::endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
 int n;
 cin>>n;
 while(n){
  int o=0,a=0,b=0;
  while(o!=3){
   string s;
   cin>>s;
   if(s=="HIT"){
    if(b==3)a++;
    else b++;
   }
   else if(s=="OUT")o++;
   else{
   a+=++b;
   b=0;
   }
  }
  cout<<a<<endl;
  n--;
 }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(void){
	int n;

	cin >> n;
	while(n-->0){
		int hits = 0;
		int inningScore = 0;
		int outNum = 0;
		while( outNum < 3 ){
			string s;
			cin >> s;
			if( s.compare("HIT") == 0 ){
				hits++;
				if( hits == 4 ){
					inningScore++;
					hits = 3;
				}
			}else if( s.compare("HOMERUN") == 0 ){
				inningScore += hits + 1;
				hits = 0;
			}else if( s.compare("OUT") == 0 ){
				outNum++;
				/* inning end */
				if( outNum == 3 ) break;
			}
		}
		cout << inningScore << '\n';
	}
	return 0;
}

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

using namespace std;

int main() {
	int base = 0;
	int out = 0;
	int score = 0;
	int inning;
	string evt;
	cin >> inning;
	while (inning) {
		cin >> evt;
		if (evt == "HIT") {
			base <<= 1;
			base |= 1;
			if (base > 7) {
				score++;
				base &= 7;
			}
		} else if (evt == "HOMERUN") {
			score++;
			for (int i = 0; i < 4; i++) {
				if ((base >> i) & 1) {
					score++;
				}
			}
			base = 0;
		} else {
			if (++out >= 3) {
				cout << score << endl;
				base = score = out = 0;
				inning--;
			}
		}
		printf(" %d %d %d\n", base, out, score);
	}
	return 0;
}

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

int main(){
    int n;
    string a;
    cin>>n;
    for(int i=0; i<n; i++){
        int hit[3]={};
        int score= 0;;
        int out = 0;
        while(cin>>a){
            if(a=="HIT"){
                if(hit[2]==1)score++;
                hit[2]=hit[1];
                hit[1]=hit[0];
                hit[0]=1;
            }
            if(a=="HOMERUN"){
                score++;
                for(int t=0; t<3; t++){
                    if(hit[t]==1){
                        score++;
                        hit[t]=0;
                    }
                }
            }
            if(a=="OUT"){
                out++;
            }
            if(out==3)break;
        }
        cout<<score<<endl;
}
    return 0;
}

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

using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int pcnt,rcnt,ocnt;
    pcnt = rcnt = ocnt = 0;
    while(ocnt < 3){
      char order[100];
      cin>>order;
      switch (order[1]){
      case 'I' : rcnt ++;break;
      case 'U' : ocnt ++;break;
      case 'O' : pcnt += rcnt + 1; rcnt = 0;break;
      }
      if(rcnt==4){
        rcnt --;
        pcnt ++;
      } 
//    cout<<pcnt<<" "<<rcnt<<endl;
    }
    cout<<pcnt<<endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  int out=0,b=0,p= 0;
  while(n){

    while(1){
      cin >> s;
      if(s == "OUT" && out == 2){
	out = 0; b = 0;
	cout << p << endl;
	p = 0;
	break;
      } 
      if(s == "OUT") out++;
      if(s == "HIT"){
	if(b == 3 ) p++;
	else b++;
      }
      if(s == "HOMERUN"){
	p += b + 1;
	b = 0;
      }
    }
    n--;
  }

  return 0;
}

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

using namespace std;

bool state[3];
int point;
int out_count;

int init() {
    point = 0;
    out_count = 0;
    for (int i = 0; i < 3; i++) 
        state[i] = false;
}

void hit() {
    if (state[2]) point++;
    if (state[1]) state[2] = true;
    if (state[0]) state[1] = true;
    state[0] = true;
}

void homerun() {
    point++;
    for (int i = 0; i < 3; i++) {
        if (state[i]) {
            point++;
            state[i] = false;
        }
    }
}

void out() {
    out_count++;
}

void solve() {
    init();
    string s;
    while (cin >> s) {
        if (s == "HIT") hit();
        else if (s == "HOMERUN") homerun();
        else if (s == "OUT") {
            out();
            if (out_count == 3) {
                cout << point << endl;
                break;
            }
        }
    }
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
    return 0;
}

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

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

  while(T--){
    string s;
    int ans = 0;
    int out = 0;
    bool first=false,second=false,third=false;

    while(cin>>s){
      if(s == "HIT"){
        if(third) ans++;
        third = second;
        second = first;
        first = true;
      }
      else if(s == "OUT"){
        out++;
        if(out == 3) break;
      }
      else{
        ans += first + second + third + 1;
        first = second = third = false;
      }
    }

    cout<<ans<<endl;
  }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef struct{
    int count;
    string s="OUT";
}OUT;
typedef struct{
    int count;
    string s="HOMERUN";
}HOME;
typedef struct{
    int count;
    string s="HIT";
}HIT;
typedef struct{
    int count;
}RUN;
typedef pair<int, int> pii;
int main(){
    int n; cin>>n;
    int ans=0;
    OUT out; HOME home; HIT hit; RUN run;
    out.count=0; home.count=0; hit.count=0; run.count=0;
    string temp;
    while(cin>>temp){
        if(temp==home.s){
            ans+=run.count+1;
            run.count=0;
        }
        if(temp==hit.s){
            run.count++;
            if(run.count>3){ans++; run.count-=1;}
        }
    if(temp==out.s){
        out.count++;
        if(out.count%3==0){cout<<ans<<endl;ans=0;run.count=0;}
        if(out.count==(n*3))return 0;
    }
    }
}