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;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        int outCount=0, base=0, point=0;
        while(outCount < 3){
            char event[8]={0};
            scanf("%s",event);
            if(event[1] == 'I'){
                base <<= 1;
                base |= 1;
                if(base & 8){
                    point++;
                    base ^= 8;
                }
            }else if(event[0] == 'H'){
                int runnerCnt=1;
                while(base > 0){
                    if(base & 1)runnerCnt++;
                    base >>= 1;
                }
                point += runnerCnt;
            }else{
                outCount++;
            }
        }
        printf("%d\n",point);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int time;
    cin >> time;
    rep(t,time){
        int base[3], old[3];
        int out = 0, point = 0;
        rep(i,3) base[i] = 0;
        string s;
        while(cin >> s){
            if(s == "HIT"){
                old[0] = base[0];
                old[1] = base[1];
                old[2] = base[2];
                if(old[0]) base[1] = 1;
                if(old[1]) base[2] = 1;
                if(old[2]) point++;
                base[0] = 1;
            }
            if(s == "HOMERUN"){
                point++;
                if(base[0]) point++;
                if(base[1]) point++;
                if(base[2]) point++;
                base[0] = 0;
                base[1] = 0;
                base[2] = 0;
            }
            if(s == "OUT"){
                out++;
                if(out == 3) break;
            }

        }
        cout << point << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  int points[n];
  for(int i=0;i<n;i++){
    bool base[3]={false,false,false};int outs=0;
    string action;int point=0;
    while(outs!=3){
      cin>>action;
      if(action=="HIT"){
        if(base[0]==false)base[0]=true;
        else if(base[1]==false)base[1]=true;
        else if(base[2]==false)base[2]=true;
        else point++;
      }
      else if(action=="HOMERUN"){
        int runner=0;
        for(int k=0;k<3;k++){
          if(base[k]==true)runner++;
        }
        for(int k=0;k<3;k++){
          base[k]=false;
        }
        point=point+runner+1;
      }
      else if(action=="OUT"){
        outs++;
      }
    }
    points[i]=point;
  }
  for(int i=0;i<n;i++){
    cout<<points[i]<<endl;
  }
}

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

//class
class Baseball{
public:
	int firstbase, secondbase, thirdbase;
	int inningNumber, out, score;

	Baseball(int num){
		inningNumber = num;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		out = 0;
		score = 0;
	}

	void playball(){
		for(int i = 0; i < inningNumber; ++i)
			inning();
	}

	void inning(){
		out = 0;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		score = 0;

		while(out != 3){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				hit();
			if(str == "HOMERUN")
				homerun();
			if(str == "OUT")
				out++;
		}

		std::cout << score << std::endl;
	}

	void hit(){
		score += thirdbase;
		thirdbase = secondbase;
		secondbase = firstbase;
		firstbase = 1;
	}

	void homerun(){
		score += thirdbase + secondbase + firstbase + 1;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
	}
};
//main
int main(){
	int n;
	std::cin >> n;
	
	Baseball *baseball = new Baseball(n);
	baseball->playball();
	delete baseball;

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int o = 7;
		int point = 0;
		int stt = 0;
		while (o > 0){
			string s;
			cin >> s;
			if (s.compare("HIT") == 0) {
				if (stt & 4) {
					point++;
				}
				stt = (stt << 1) | 1;
			} else if (s.compare("HOMERUN") == 0) {
				while (stt > 0) {
					point++;
					stt = stt >> 1;
				}
				point++;
			} else if (s.compare("OUT") == 0) {
				o = o >> 1;
			}
		}
		cout << point << endl;
	}
	return 0;
}

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

class Baseball{
	private:
	int out;
	int runner;
	int point;

	public:
	void init();
	int get_out();
	int get_point();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::init(){
	out = 0;
	runner = 0;
	point = 0;
}

int Baseball::get_out(){
	return out;	
}

int Baseball::get_point(){
	return point;
}

void Baseball::event_hit(){
	if(runner == 3){
		++point;
	}else{
		++runner;
	}
}

void Baseball::event_homerun(){
	point += ++runner;
}

void Baseball::event_out(){
	++out;
}

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	Baseball base;
	base.init();
	for(int i = 0; i < num; ++i){
		while(base.get_out() < 3){
			std:: cin >> event;

			if(event == "OUT"){
				base.event_out();		
			}else if(event == "HIT"){
				base.event_hit();
			}else if(event == "HOMERUN"){
				base.event_homerun();
			}
		}
		std::cout << base.get_point() << std::endl;
		base.init();
	}
	return 0;
}

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

int main()
{
	int n,count,point,out;
	string s;
	cin >> n;
	while(n--){
		point = count = out = 0;
		while(out < 3){
			cin >> s;
			if(s=="OUT"){
				out++;
			}else if(s=="HIT"){
				count++;
				if(count>3){
					point++;
					count--;
				}
			}else{
				point += count + 1;
				count = 0;
			}
		}
		cout << point << endl;
	}
}

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

using namespace std;

int main()
{
	string str;
	int n;
	int E=0,out=0,score=0,base=0;
	
	cin >> n ;
	for(;;)
	{
		if(E==n)
			break;
		cin >> str ;
		if(str=="OUT")
		{
			out++;
		}
		else if(str=="HIT")
		{
			base++;
			if(base==4)
			{
				score++;
				base--;
			}
		}
		else
		{
			score+=base+1;
			base=0;
		}
		
		if(out==3)
		{
			cout << score << endl;
			out=base=score=0;
			E++;
		}
	}
}

C++: #include<iostream>
#include<vector>
int main(){
	int n,m=0,n2=0,s1=0,s2=0;
	std::cin>>n;
	int o=0;
	std::vector<int> vec(3);
	while(n>m){
		std::string str;
		std::cin>>str;
		if(str=="HIT"&&n2%2==0){
			if(vec[2]==1)s1++,vec[2]=0;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HIT"&&n2%2==1){
			if(vec[2]==1)s2++,vec[2]=0;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HOMERUN"&&n2%2==0){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s1++;
				vec[i]=0;
			}
			s1++;
		}
		if(str=="HOMERUN"&&n2%2==1){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s2++;
				vec[i]=0;
			}
			s2++;
		}
		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,n2++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	std::cout<<s1<<std::endl<<s2<<std::endl;
	return 0;
}