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 <iostream>
#include <string>
using namespace std;
int main(void){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int out=0,base=0,point=0;
		while(out<3){
			string event;
			cin >> event;
			if(event == "OUT"){
				out++;
			}else if(event == "HIT"){
				if(base == 3){
					point++;
				}else{
					base++;
				}
			}else{
				point += base + 1;
				base = 0;
			}
		}
		cout << point << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  while(n--){
    int runner = 0;
    int out = 0;
    int point = 0;
    
    while(out<3) {
      string s;
      cin >> s;
      
      if(s=="HIT"){
	runner++;
      }

      else if (s=="OUT"){
	out++;
      }

      else if (s=="HOMERUN"){
	point+=runner+1;
	runner = 0;
      }
      
      if(runner == 4) {
	point++;
	runner = 3;
      }
      
    }
    cout << point << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		int out = 0;
		int num_runner = 0;
		int points = 0;

		while(true){
#if INPUT_FROM_FILE
			ifs >> buf;
#else
			std::cin >> buf;
#endif
			if(buf == "HIT"){
				if(num_runner == 3){
					points++;
				}
				else{
					num_runner++;
				}
			}
			else if(buf == "HOMERUN"){
				points += num_runner + 1;
				num_runner = 0;
			}
			else{
				out++;
				if(out == 3){
					std::cout << points << std::endl;
					break;
				}
			}
		}
	}

#if INPUT_FROM_FILE
		//fclose(fp);
#endif
	return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>
#include <string>
/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	string order;
	int baseman[4];
	int point;
	int out_count;
	/*****処理部*****/
	int n;
	cin >> n;
	for(int loop = 0;loop<n;loop++){
		point = 0;
		out_count=0;
		for(int i=0;i<4;i++){
			baseman[i] = 0;
		}
		while(out_count != 3){
			baseman[0] = 1;
			cin >> order;
			if(order == "HIT"){
				if(baseman[3] == 1)	point++;
				for(int i=3;i>0;i--){
					baseman[i] = baseman[i-1];
				}
			}else if(order == "OUT"){
				out_count++;
			}else if(order == "HOMERUN"){
				for(int i=0;i<4;i++){
					if(baseman[i] == 1)	point++;
					baseman[i] = 0;
				}
			}
		}
		cout << point << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

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

int main(){
	string str;
	int n;
	getline( cin, str );
	sscanf( str.c_str(), "%d", &n );

	for( int i=0; i<n; i++ ){
		int out = 0;
		int score = 0;
		bool first=false, second=false, third=false;

		while( out < 3 ){
			getline( cin, str );
			if( str == "HIT" ){
				if(third){ score++; third=false; }
				if(second){ third=true; second=false; }
				if(first){ second=true; first=false; }
				first = true;
			}
			else if( str == "HOMERUN" ){
				if(third){ score++; third=false; }
				if(second){ score++; second=false; }
				if(first){ score++; first=false; }
				score++;
			}
			else if( str == "OUT" ){
				out++;
			}
		}
		cout << score << endl;
	}
}

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

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

    string temp; getline(cin, temp);

    for (int n = 0; n != N; ++n) {
        string event;
        int runners = 0, points = 0, out = 0;
        
        while (cin >> event && out < 3) {
            if (event == "HIT") {
                if (runners == 3) {
                    points++;
                }
                else {
                    runners++;
                }
            }
            else if (event == "HOMERUN") {
                points += runners + 1;
                runners = 0;
            }
            else if (event == "OUT") {
                out++;
            }
        }
        cout << points << endl;
    }
}

C++: //0103
#include<string.h>
#include<stdio.h>
int main()
{
	int n,op,rn[3]={0},r;
	char s[8];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		r=0;
		op=0;
		while(1){
			if(strcmp("OUT",s)==0){
				op++;
			}else if(strcmp("HIT",s)){
				if(rn[2]){
					rn[2]=0;
					r++;
				}
				if(rn[1]){
					rn[1]=0;
					rn[2]=1;
				}
				if(rn[0]){
					rn[1]=1;
				}
				rn[0]=1;
			}else{
				for(int j=0;j<3;j++){
					if(rn[j]==1){
						rn[j]=0;
						r++;
					}
					r++;
				}
			}
			if(op>=3){
				break;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int main(){
    int hit, out, score, data_set_num;
    std::string event;
    std::getline(std::cin,str);
    sscanf(str.c_str(),"%d ",&data_set_num);

    while(data_set_num--){
        std::cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                hit = 3;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            score = 0;
        }
    }

    return 0;
}

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

using namespace std;

int main() {

	int N;
	cin >> N;

	for (int i = 0; i < N; i++) {

		int out = 0, point = 0, a[4] = {};
		string event;

		while (out < 3) {
			cin >> event;

			if (event == "HIT") {
				a[3] = a[2];
				a[2] = a[1];
				a[1] = a[0];
				a[0] = 1;
				if (a[3] == 1) {
					point++;
					a[3] = 0;
				}
			}
			if (event == "HOMERUN") {
				for (int j = 0; j < 3; j++) {
					if (a[j] == 1) {
						point++;
					}
					a[j] = 0;
				}
				point++;
			}
			if (event == "OUT") {
				out++;
			}
		}
		cout << point << endl;
	}

	return 0;
}

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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int base = 0, out = 0, point = 0;
		while (out != 3) {
			string s;
			cin >> s;
			if (s == "HIT") {
				if (base == 3) {
					point++;
				}
				else if (base < 3) {
					base++;
				}
			}
			else if (s == "HOMERUN") {
				point += base + 1;
				base = 0;
			}
			else {
				out++;
			}
		}
		cout << point << endl;
	}
}