Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,outcnt=0,out=0,i=0,flag[3]={0};
  cin>>n;
  int ining[n]={0};
  while(out!=(n*3)){
    string jugde;
    cin>>jugde;
    if(jugde=="OUT"){
      outcnt++;out++;
      if(outcnt==3){
	for(int j=0;j<3;j++)
	  flag[j]=0;
	i++;
	outcnt=0;
      }
    }
    if(jugde=="HIT"){
      if(flag[2]==1)
	ining[i]++;
      if(flag[1]==1)
	flag[2]=1;
      if(flag[0]==1)
	flag[1]=1;
      flag[0]=1;
    }
    if(jugde=="HOMERUN"){
      int point=0;
      for(int j=0;j<3;j++){
	if(flag[j]==1)
	  point++;
	flag[j]=0;
      }
      ining[i]+=(point+1);
    }
  }
  for(int j=0;j<n;j++){
    cout<<ining[j]<<endl;
  }
  return 0;
}

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;
  }
}