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>
#include <fstream>

int main(){
    int hit = 0, out= 0, score = 0, data_set_num;
    std::string event, str;
    std::cin >> data_set_num;
    std::cin.ignore();

    while(data_set_num){
        std::cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                --hit;
            }
        }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;
            out = 0;
            --data_set_num;
        }
    }

    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
 
int main(){
        int o,i,out=0,b=0,p[100];
        string ev;
        
        cin >> o;
 
        for(i=0; i<o; i++){
 
                p[i] = 0;
 
                while(1){
 
                        cin >> ev;
                        
                        if(ev=="HIT"){
                                b++;
                                
                                if(b==4){
                                        b--;
                                        
                                        p[i]++;
                                }
                        }
                        
                        else if(ev=="HOMERUN"){
                                p[i] += b+1;
                                
                                b=0;
                        }
                        
                        else if(ev=="OUT"){
                                out++;
                        }
 
                        if(out==3) break;
                }
                
                out=0;
                b=0;
        }
 
        for(i=0; i<o; i++){
                cout << p[i] << endl;
        }
 
  return 0;
}

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

int main(){
  int n,ansc=0,o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;

  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;

    if(o2==3*n)break;

    if(h==4){
      ansc++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
    }
    else if(hr==1){
      ansc+=h+1;
      h=0;
      hr=0;
    }
    i++;
  }
  cout<<ansc<<endl;
  return 0;
}

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

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n));

int main(){
	int n;
	cin>>n;
	while(n){
		int out=0;
		int ans=0;
		int rui=0;
		while(out!=3){
			string s;
			cin>>s;
			if(s=="HIT"){
				if(rui==3){
					ans++;
				}
				else{
					rui++;
				}
			}
			else if(s=="OUT"){
				out++;
			}
			else{
				ans+=rui;
				ans++;
				rui=0;
			}
		}
		cout<<ans<<endl;
		n--;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int casenum;
int runner,strike,out,point;
string str;


int main(){
  cin >> casenum;
  for(int i = 0;i < casenum;i++){
    runner = strike = out = point = 0;
    while(1){
      cin >> str;
      if(str == "HIT"){
	strike = 0;
	if(runner == 3)point += 1;
	else runner++;
      }else if(str == "OUT"){
	out++;
	strike = 0;
	if(out == 3)break;
      }else if(str == "HOMERUN"){
	point += (runner+1);
	runner = strike = 0;
      }
    }
    cout << point << endl;
  } 
  return 0;
}

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

int main(){
	int o,i,out=0,b=0,p[10];
	string ev;
	
	cin >> o;

	for(i=0; i<o; i++){

		p[i] = 0;

		while(1){

			cin >> ev;
			
			if(ev=="HIT"){
				b++;
				
				if(b==4){
					b--;
					
					p[i]++;
				}
			}
			
			else if(ev=="HOMERUN"){
				p[i] += b+1;
				
				b=0;
			}
			
			else if(ev=="OUT"){
				out++;
			}

			if(out==3) break;
		}
		
		out=0;
		b=0;
	}

	for(i=0; i<o; i++){
		cout << p[i] << endl;
	}

  return 0;
}

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

int main()
{
   int n, outcnt = 0, point = 0;
   string str;

   queue<bool> que;

   cin >> n;

   for( int i = 0; i < n; ++i )
   {
      while(outcnt != 3)
      {
         cin >> str;

         if( str == "HIT" )
         {
            que.push(true);
            if( que.size() == 4 )
            {
               que.pop();
               ++point;
            }
         }
         else if( str == "HOMERUN" )
         {
            point += que.size() + 1;
            while( !que.empty() ) que.pop();
         }
         else if( str == "OUT" )
         {
            ++outcnt;
         }
      }
      cout << point << endl;
      point = 0;
   }
}

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

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

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

	//getter
	int getOut() { return out; }
	int getRunner() { return runner; }
	int getScore() { return score; }

	//input OUT
	void execOut() { ++out; }

	//input HIT
	void execHit() {
		if(runner == 3)++score;
		else ++runner;
	}

	//input HOMERUN
	void execHomerun() {
		score += runner + 1;
		runner = 0;
	}

};

int main(){
	int dataSetNum;
	std::cin >> dataSetNum;

	std::vector< Baseball > baseball;
	baseball.resize(dataSetNum);

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

		while(baseball[i].getOut() != 3){
			
			//input
			std::string tmp;
			std::cin >> tmp;

			if(tmp == "OUT")baseball[i].execOut();
			else if(tmp == "HIT")baseball[i].execHit();
			else if(tmp == "HOMERUN")baseball[i].execHomerun();
		}

	}
	//output
	std::for_each(baseball.begin(), baseball.end(),
    [](Baseball x) { std::cout << x.getScore() << std::endl; } );

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long n,r,p,o,i;
string s;
cin>>n;
for(i=0;i<n;i++){
o=p=r=0;
while(cin>>s){
if(s=="HIT"){
r*=2;r++;if(r>=8){p++;r-=8;}
}else if(s=="HOMERUN"){
if(r==1||r==2||r==4)p+=2;
else if(r==3||r==5||r==6)p+=3;
else if(r==7)p+=4;
r=0;
}else if(s=="OUT"){
o++;
if(o>=3)break;
}
}
cout<<p<<endl;
}
return 0;
}

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

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int b=0,ans=0,out=0;
    for(string s;cin>>s;){
      if(s=="HIT"){
	b++;
	if(b==4){
	  ans++;
	  b=3;
	}
      }else if(s=="OUT"){
	out++;
	if(out==3)break;
      }else{
	ans+=b+1;
	b=0;
      }
    }
    cout<<ans<<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 hit = 0, out = 0, point = 0;
		string event;
		while( cin >> event ){
			if( event == "HIT" ){
				hit++;
				if( hit == 4 ){
					point++;
					hit--;
				}
			}else if( event == "HOMERUN" ){
				point += hit+1;
				hit = 0;
			}else if( event == "OUT" ) out++;
			
			if( out == 3 ) break;
		}
		cout << point << endl;
	}
}