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<algorithm>
using namespace std;
int main(){
        vector<int> point,runner;
        int d;
        string s;
        cin>>d;
        point.reserve(d);
        runner.reserve(d);
        for(int j = 0 ; j < d ; j++){
        fill(point.begin(),point.end(),0);
        fill(runner.begin(),runner.end(),0);
        for(int i=0; i < 3;){
                
                cin>>s;
                
                        if(s=="HIT"){
                        runner[j]++;
                                if(runner[j]>3){
                                        runner[j]--;
                                        point[j]++;
                                }
                        }
                        else if(s=="HOMERUN"){
                        point[j] += (1 + runner[j]);
                        runner[j] =0;
                        }
                        else if(s=="OUT"){
                        i++;
                        }
                
                }
        
        }
        
        for(int i = 0;i < d; i++) cout<<point[i]<<endl; 
}

C++: #include <iostream>
using namespace std;
int main(){
  int n,rui[3],outcnt,i,j,k,point,homeruncnt;
  string data;
  cin >> n;
  for(i=0;i<n;i++){
    outcnt=0;
    homeruncnt=0;
    point=0;
    for(j=0;j<3;j++)
      rui[j]=0;
      while(1){
      cin >> data;
      if(data=="HIT"){
        if(rui[0]==0) rui[0]=1;
	else{
	  if(rui[1]==0) rui[1]=1;
          else{
	    if(rui[2]==0) rui[2]=1;
	    else point++;
	  }
	}
      }
      else if(data=="HOMERUN"){
        for(k=0;k<3;k++){
	  if(rui[k]==1){
	    homeruncnt++;
	    rui[k]=0;
	  }
	}
        point=point+homeruncnt+1;
	homeruncnt=0;
      }
      else{
        outcnt++;
      }
      if(outcnt==3){
	outcnt=0;
        cout << point << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int p, out;
int main(){
  int t;
  cin >> t;
  vector<int> v;
  string s;
  while(cin >> s){
    if(s == "HIT"){
      if(v.size()<3)v.push_back(0);
      else p++;
    }else if(s == "OUT"){
      out++;
      if(out == 3){
	cout << p << endl;
	p = out = 0;
	v.clear();
      }
    }else{
      p += v.size() + 1;
      v.clear();
    }
  }
  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;
	 switch(E){
		case "HIT":
		if(T){point++;}
		T=S;S=F;F=true;
		break;
		case "HOMERUN":
		point++;
		if(F){point++;F=false;}
		if(S){point++;S=false;}
		if(T){point++;T=false;}
		break;
		case "OUT":
		out++;
		break;
	 }
	}
	cout<<point<<endl;
	//???????????§
	}
	
	return 0;
}

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

using namespace std;

int main(){
	int n , i = 1;
	int base = 0 , sum[100] = {} , out_count = 0;
	string str;

	cin >> n;
		
	while(1){
	    
		if(i > n) break;
		cin >> str;
		
		if(out_count >= 3){
			base = 0;
			i++;
		}
		if(base >= 4){
		    sum[i]++;
		    base = base - 1;
		}
		if(str == "HIT"){base++;}
		else if(str == "OUT"){out_count++;}
		else if(str == "HOMERUN"){
		    sum[i] += base + 1;
		    base = 0;
		}
		
	}
    for(int i = 0; i < n; i++){
        cout << sum[i + 1] << endl;
    }
    
	return 0;
}

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

using namespace std;

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

C++: #include <iostream>
#include <string>
 
using namespace std;
 
// ???????????\?????????????????°??°
// 1???????????°???3??¢????????????????????§
// ????????°?????????????????´???
// 1??????????????????????????????????????°???????¶?????????????
// 3????????°??????????????´??????1???????????????
// ????????????????????´???
// 1????????°????????°?????°????????????????¶????
 
// ????????¶??????????????????
struct Diamond {
    bool first;
    bool second;
    bool third;
    Diamond() : first(), second(), third(){};
 
    int onHit() {
        int result = 0;
        if (third != false) {
            result = 1;
        }
        if (second != false) {
            third = true;
        }
        if (first != false) {
            second = true;
        }
        first = true;
        return result;
    }
    int onHomeRun() {
        // ????????§???1???????????§1??§?????????
        int result = 1;
        if (third != false) {
            result++;
        }
        if (second != false) {
            result++;
        }
        if (first != false) {
            result++;
        }
        first = false;
        second = false;
        third = false;
        return result;
    }
};
 
int main() {
 
    int n;
 
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int out_count = 0;
        int point = 0;
        Diamond dia;
        while (out_count < 3) {
            string temp;
            cin >> temp;
 
            if (temp == "HIT") {
                point += dia.onHit();
            }
            else if (temp == "HOMERUN") {
                point += dia.onHomeRun();
            }
            else {
                // ????????????OUT??¨???????????????
                out_count++;
            }
        }
        cout << point << endl;
    }
    return 0;
}

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

int main() {
	int n;
	int score=0;
	int count=0;
	int base=0;
	string d;
	cin>>n;
	for(int i=0;i<n;i++){
		while(true){
			cin>>d;
			if(d=="HIT"){
				base++;
				if(base==4){
					score++;
					base--;
				}
			}
			else if(d=="HOMERUN"){
				score=score+base+1;
				base=0;
			}
			else if(d=="OUT"){
				count++;
				if(count==3){
					count=0;
					cout<<score<<endl;
					score=0;
					base=0;
					break;
				}
			}
		}
	}
	return 0;
}

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

class Baseball{

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

public:

	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

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

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

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

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

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

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

			else if(str == "OUT")
				baseball.add_out();
			
			if(baseball.get_out() == 3){
				break;
			}
		}

	}

	return 0;
}