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 <cstdio>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main()
{
  int n;
  string input;

  scanf("%d", &n);
  for (int i = 0; i < n; i++){
    queue<bool> base;
    int out = 0, pt = 0;
    while (out < 3){
      cin >> input;
      if (input == "HIT"){
        base.push(true);
        if (base.size() == 4){
          pt += base.front();
          base.pop();
        }
      }
      else if (input == "HOMERUN"){
        pt += base.size() + 1;
        while (!base.empty()){ // all elements clear
          base.pop();
        }
      }
      else if (input == "OUT"){
        out++;
      }
    }
    printf("%d\n", pt);
  }

  return (0);
}

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

using namespace std;

int main(void){
  string str;
  int n;
  int i=0;
  int ocnt=0, bcnt=0;
  int score=0;
  cin >> n;
  while(i < n){
	cin >> str;
	if(str == "OUT"){
	  ocnt++;
	}else if(str == "HIT"){
	  if(bcnt < 3){
		bcnt++;
	  }else{
		score++;
	  }
	}else if(str == "HOMERUN"){
	  score += bcnt+1;
	  bcnt = 0;
	}
	if(ocnt == 3){
	  cout << score << endl;
	  ocnt = 0;
	  bcnt = 0;
	  score = 0;
	  i++;
	}
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int out = 3, point = 0, base[3] = {0};
    string s;
    while(out){
      cin >>s;
      if(s == "OUT"){out--;}
      if(s == "HIT"){
	if(base[2]){point++;}
	for(int i=2; i>0; i--){base[i] = base[i-1];}
	base[0] = 1;
      }
      if(s == "HOMERUN"){
	for(int i=0; i<3; i++){
	  if(base[i]){point++;}
	  base[i] = 0;
	}
	point++;
      }
    }
    cout <<point<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

#define PI 4*atan(1)

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    bool base[3] = {false};
    int point = 0, out = 0;
    while(1){
      char s[8];
      cin >> s;
      if(strcmp(s, "HIT") == 0){
        if(base[2] == true){
          point += 1;
          base[2] = false;
        }
        if(base[1] == true){
          base[1] = false;
          base[2] = true;
        }
        if(base[0] == true){
          base[0] = false;
          base[1] = true;
        }
        base[0] = true;
      }
      if(strcmp(s, "OUT") == 0){
        out++;
        if(out == 3)break;
      }
      if(strcmp(s, "HOMERUN") == 0){
        for(int j = 0; j < 3; j++){
          if(base[i] == true){
            base[i] = false;
            point++;
          }
        }
        point++;
      }
    }
    cout << point << endl;
  }
}

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


using namespace std;

class Player{
private:
  int  base;

public:
  Player(int i){
    base=1;
  }


  void SetBase(int a){
    this->base =a;
  }

  int GetBase(){
    return this->base;
  }
};

class Baseball{
private:
  int score;
  int out;
  queue<Player> que;

public:
  Baseball(){
      score = out=0;
  }

  void add_hit(int num){
    Player one(1);
    this->que.push(one);
    int length=this->que.size();

    for(int i= 0;i<length;i++){
      Player tmp = this->que.front();
      this->que.pop();
      int tmp_base=tmp.GetBase();
      if((tmp_base+num)>4){
        score++;
      }else{
        tmp.SetBase(tmp_base+num);
        this->que.push(tmp);
      }
    }
  }

  void add_out(){
    this->out++;
  }

  void add_score(){
    this->score++;
  }

  int GetOut(){
    return this->out;
  }

  int GetScore(){
    return this->score;
  }

  void show_score(){
    cout<<this->score<<endl;
  }

};

int main(void){
  int time;
  cin >> time;

  for(int i=0;i<time;i++){
    Baseball baseball;
    while(baseball.GetOut()!=3){
      string judge;
      cin>>judge;
      if(judge == "HIT"){
        baseball.add_hit(1);
      }else if(judge=="OUT"){
        baseball.add_out();
      }else if(judge=="HOMERUN"){
        baseball.add_hit(4);
      }

    }

    cout<<baseball.GetScore()<<endl;
  }

  return 0;
}

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

class GameStatus{
public:
	int score;
	int out;
	queue<int> base;

	GameStatus(){
		score = 0;
		out = 0;
		for (int i = 0; i < 3; i++)
			base.push(0);
	}

	void Hit(){
		score += base.front();
		base.pop();
		base.push(1);
	}

	void Homerun(){
		for (int i = 0; i < 3; i++){
			score += base.front();
			base.pop();
			base.push(0);
		}

		score++;
	}
};

int main(){
	const string es[3] = { "HIT", "HOMERUN", "OUT" };
	int n;
	cin >> n;

	while (n){
		GameStatus gs;
		string e;
		while (gs.out < 3){
			cin >> e;
			if (e == es[0])
				gs.Hit();
			else if (e == es[1])
				gs.Homerun();
			else if (e == es[2])
				gs.out++;
		}
		cout << gs.score << endl;
		n--;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
vector<string> v;
int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		v.clear();
		int out=0;
		while(1)
		{
			string s;
			cin >> s;
			if(s=="OUT")
			{
				out++;
			}
			else
			{
				v.pb(s);
			}
			if(out==3)break;
		}
		int point=0,runner=0,f=0,s=0,t=0;
		for(int j=0;j<v.size();j++)
		{
			if(v[j]=="HIT")
			{
				if(t)
				{
					point++;
					runner--;
				}
				t=s;
				s=f;
				f=1;
				runner++;
			}
			else
			{
				f=0;s=0;t=0;
				point+=(runner+1);
				runner=0;
			}
		}
		cout << point << endl;
	}
	return 0;
}

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

int main()
{
	string buf;
	getline(cin, buf);
	int N;
	N = stoi(buf);
	int runCount = 0;
	int Run = 0;
	int outCount = 0;

	while(1)
	{
		if(N == 0)
		{
			return 0;
		}
		string str;
		getline(cin, str);
		if(str == "HOMERUN")
		{
			Run += runCount + 1;
			runCount = 0;
		}
		else if(str == "HIT")
		{
			runCount++;
			if(runCount == 4)
			{
				Run++;
				runCount = 3;
			}

		}
		else if(str == "OUT")
		{
			outCount++;
			if(outCount == 3)
			{
				cout << Run << endl;
				outCount = 0;
				runCount = 0;
				Run = 0;
				N--;

			}

		}

	}



}

C++: main(){
	int c,y,t,o,p;
	char a[9];
	scanf("%d",&c);
	for(y=0;y<c;y++){
		for(t=o=p=0;;){
			scanf("%s",a);
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}c=1;
}

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

int main()
{
	int point, base, n, out;
	char ibe[10];

	cin >> n;
	for (int k = 0; k < n; k++){
		base = point = out = 0;
		while (out != 3){
	 	 cin >> ibe;
		 if (ibe[0] == 'H' && ibe[1] == 'I' && ibe[2] == 'T'){
			 base++;
			 if (base == 4){
				 base--;
				 point++;
			 }
		 }
		 else if (ibe[0] == 'O'){
			 out++;
		 }
		 else {
			 point += base;
			 base = 0;
		 }
		}
		cout << point << endl;
	}
	return (0);
}