Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

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

int main() {
  int n;
  cin >> n;
  string t;
  queue<string> que;
  while(cin >> t) que.push(t);
  int out=0,run=0,point=0;
  while(!que.empty()) {
    if(n==0) break;
    string s=que.front();
    que.pop();
    if(s=="HIT") {
      run++;
      if(run==4) {
	point++;
	run=3;
      }
    } else if(s=="HOMERUN") {
      run++;
      point+=run;
      run=0;
    } else {
      out++;
      if(out==3) {
	n--;
	run=0;
	out=0;
	cout << point << endl;
	point=0;
      }
    }
  }
  return 0;
}

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

//0103
int main(){
	int n;
	string s;

	cin >> n;
	int point=0;
	int out=0;
	int base[3]={0, 0, 0};

	while(cin >> s){

		if(s=="HIT"){
			if(base[2]==1){
				++point;
				base[2]=0;
			}
			if(base[1]==1){
				base[2]=1;
				base[1]=0;
			}
			if(base[0]==1){
				base[1]=1;
				base[0]=0;
			}
			base[0]=1;

		}else if(s=="HOMERUN"){
			for(int i=0; i<3; ++i){
				point += base[i];
			}
			point++;
			base[0]=0;
			base[1]=0;
			base[2]=0;

		}else{
			++out;
			if(out>=3){
				cout << point << endl;
				point=0;
				out=0;
				base[0]=0;
				base[1]=0;
				base[2]=0;
				continue;
			}
		}
		
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    string ins;
    cin>>n;
    for(int ix=0;ix<n;ix++){
        int out=0,po=0;
        vector<bool> runner(3,false);
        for(;;){
            cin>>ins;
            if(ins=="HIT"){
                if(runner[2]){
                    po++;
                    runner[2]=false;
                }
                if(runner[1]){
                    runner[2]=true;
                    runner[1]=false;
                }
                if(runner[0]) runner[1]=true;
                runner[0]=true;
            }else if(ins=="OUT"){
                out++;
                if(out==3)break;
            }else if(ins=="HOMERUN"){
                po++;
                for(int i=0;i<3;i++){
                    if(runner[i])po++;
                    runner[i]=false;
                }
            }
        }
        cout<<po<<enld;
        printf("%d\n",po);
    }
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,o,h,p;
	char s[8];
	scanf("%d",&n);
	o=h=p=0;
	while(n>0){
		scanf("%s",s);
		if(s[1]=='I'){
			h++;
			if(h>3){p++;h--;}
		}else if(s[1]=='U'){
			o++;
			if(o>2){
				printf("%d\n",p);
				o=h=p=0;
				n--;
			}
		}else if(s[1]=='O'){
			p+=h+1;
			h=0;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  int hit,out;
  int score;
  string c;
  cin >> n;
  for(int i=0;i<n;i++){
    hit = 0; 
    out = 0;
    score = 0;
    while(out!=3){
      cin >> c;
      if(c=="HIT"){
	hit++;
	if(hit==4){
	  score += 1;
	  hit = 3;
	}
      }
      else if(c=="HOMERUN"){
	score += (hit+1);
	hit =  0;
      }
      else out++;
    }
    cout << score << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	string batter;
	int n;

	cin >> n; 

	for(int i = 0; i < n; i++){
		int runner = 0 , num = 0 , out = 0;	
		while(1){
			cin >> batter;

			if(batter == "HIT"){
				runner++;
				if(runner == 4){
					runner--;
					num++;
				}
			}else if(batter == "HOMERUN"){
				num++;
				num += runner;
				runner = 0;
			}else if(batter == "OUT"){
					out++;
					if(out == 3){
						runner = 0;
						break;
					}
				}
			}
		cout << num << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(void)
{
  char str[16]={};
  int n;
  int i;
  int score=0;
  int base=0;
  int out=0;

  scanf("%d", &n);

  for(i=0;i<n;i++)
    {
      score=0;
      base=0;
      out=0;
      while(1)
        {
          scanf("%s", str);
          if(str[1]=='I')
            if(base==3)
              score++;
            else
              base++;
          else if(str[1]=='U')
            if(out==2)
              break;
            else
              out++;
          else if(str[1]=='O')
            {
              score+=(base+1);
              base=0;
            }
        }
      printf("%d\n", score);
    }
  return 0;
}

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

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

C++: #include <iostream>

class Baseball{
private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(){
		point = 0;
		out = 0;
		base = 0;
	}

	int point(){
		return point;
	}

	int out(){
		return out;
	}

	int hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	int home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	int get_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

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

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

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT")
				baseball.get_out();

		}

		std::cout >> baseball.point() >> endl;
	}

	return 0;
{

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

int main(){
	bool F,S,T;
	int out,point;
	
	int i,j;
	
	int dataN,dataLoop;
	string E;
	
	cin>>dataN;
	for(dataLoop=0;dataLoop<dataN;dataLoop++){
	out=0;point=0;
	while(out!=3){
	 cin>>E;
	 if(E=="HIT"){
	  if(T){point++;}
	  T=S;S=F;F=true;
	 }else if(E=="HOMERUN"){
	  point++;
	  if(F){point++;F=false;}
	  if(S){point++;S=false;}
	  if(T){point++;T=false;}
	 }else{
	  out++;
	 }
	}
	cout<<point<<endl;
	}
	
	return 0;
}

C++: #include <iostream>

int main(int argc, const char * argv[]) {
    int k;
    int out = 0;
    int hit = 0;
    int numrun = 0;
    int pointa = 0;
    int pointb = 0;
    int ining = 0;
    
    std::cin >> ining;
    int i = 1;
    while(i < ining + 1){
        std::string judge;
        std::cin >> judge;
        
        if(judge == "HIT"){
            hit++;
            if(hit == 4){
                pointa++;
                hit = hit - 1;
            }
        }
        
        if(judge == "OUT"){
            out++;
            if(out >= 3){
                i++;
                std::cout << pointa << std::endl;
                hit = 0;
                out = 0;
                pointa = 0;
            }
        }
        
        if(judge == "HOMERUN"){
            pointa = pointa + hit + 1;
            hit = 0;
        }
  }
}