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>
using namespace std;
int main(void){
	int 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 <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

void hit(int base[], int& score){
	if(base[2] == 1){
		score++;
		base[2] = 0;
	}
	if(base[1] == 1){
		base[2] = 1, base[1] = 0;
	}
	if(base[0] == 1){
		base[1] = 1;
	}
	base[0] = 1;

	return ;
}

void homerun(int base[], int& score){
	score += base[0] + base[1] + base[2] + 1;
	base[0] = base[1] = base[2] = 0;
	return ;
}

int main(void){
	int n;
	cin >> n;

	for(int i=0; i<n; ++i){
		int score = 0, out = 0;
		int base[3] = {0};
		string s;
		while(1){
			cin >> s;
			if(s == "HIT")
				hit(base, score);
			if(s == "HOMERUN")
				homerun(base, score);
			if(s == "OUT"){
				out++;
				if(out == 3){
					cout << score << endl;
					break;
				}
			}
		}
	}


	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,ground,ou,point;
  string s;
  
  scanf("%d",&n);
  
  for(int cas=0;cas<n;cas++){
    ground = ou = point = 0;
    while(1){
      cin >> s;
      if(s == "OUT"){
	ou++;
	if(ou == 3) break;
      } else if(s == "HIT"){
	ground<<=1;
	ground|=1;
	if(ground >= (1<<3)){
	  ground&=(~(1<<3));
	  point++;
	}
      } else{
	for(int i=0;i<3;i++){
	  if(ground&(1<<i)) point++;
	}
	ground=0;
	point++;
      }
    }
    cout << point << endl;
  }
  
  return 0;
}

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

int main()
{
	int n,inning=0;
	int p[40] = {0};
	string ivent;

	cin >> n ;
	while (1)
	{
		int r=0, o=3;                        //r = ???????????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p[inning]++;
                                        r=3;
				}
			}

			else if (ivent=="HORMRUN")
			{
				p[inning] += r + 1;
				r = 0;                            //??????????????????????????????
			}
			else if (ivent=="OUT")
			{
				o--;
			}
		}
		cout << p[inning] << endl;
		inning++;
		if (n == inning) break;

	}

	return 0;
}

C++: #include<iostream>
#include<string>
#define RU 5
#define LIMIT 100
using namespace std;

int main () {

	int ru[RU];	

	
	string in;
	int n;
	cin >> n;
	for ( int j=0; j<n; j++ ) {
		for ( int i=0; i<RU; i++ ) {
			ru[i] = 0;
		}
		int out = 0;
		int score = 0;
		while ( true ) {
			cin >> in;
			if ( in.compare("HIT") == 0 ) {
				for ( int i=2; i>=0; i-- ) {
					ru[i+1] = ru[i];
				}
				ru[0] = 1;
				if ( ru[3] != 0 ) {
					score++;
					ru[3] = 0;
				}
			}
			if ( in.compare("HOMERUN") == 0 ) {

				for ( int i=0; i<3; i++ ) {
					if ( ru[i] != 0 )
						score++;
					ru[i] = 0;
				}
				score++;
			}
			if ( in.compare("OUT") == 0 ) {
				//cout << "T OUT" << endl;
				out++;
			}
			if ( out == 3) {
				cout << score << endl;
				break;
			}
		}
	}


}

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

int Baseball()
{
    int num_of_runner = 0, num_of_out = 0, point = 0;
    std::string event;
    while(num_of_out != 3){
        std::cin >> event;
        switch(event){
            case HIT:
                if(num_of_runner == 3);
                    ++point;
                else
                    ++num_of_runner;
                break;
            case HOMERUN:
                point += 1 + num_of_runner;
                num_of_runner = 0;
                break;
            case OUT:
                ++num_of_out;
                break;
        }
    }
    
    return point;
}

int main()
{
    u_int num_of_inning;
    std::cin >> num_of_inning;
    
    for(u_int i = 0; i < num_of_inning; ++i){
        std::cout << Baseball() << std::endl;
    }
    
    return 0;
}

C++: #include <iostream>
using namespace std;
void HIT(void);
void HOMERUN(void);
void OUT(void);

int main(void){
    int data, score, out, first, second, third;
    string event;
    
    cin >> data;
    for(int i=0; i<data; i++){
        out=0;
        score=0;
        first=0;
        second=0;
        third=0;
        
        while(out<3){
            cin >> event;
            if(event=="HIT"){
                if(third==1){
                    third=0;
                    score++;
                }
                if(second==1){
                    third=1;
                    second=0;
                }
                if(first==1){
                    second=1;
                    first=0;
                }
                first=1;
            }
            else if(event=="HOMERUN"){
                int count=0;
                if(first==1) count++;
                if(second==1) count++;
                if(third==1) count++;
                score += count+1;
                first=0;
                second=0;
                third=0;
            }
            else if(event=="OUT"){
                out++;
            }
        }
        cout << score << endl;
    }
    return 0;
}

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

int main(void){
  string res;
  int n,cnt=0,cntH=0,point=0;

    cin >> n;
  for( int i = 0 ; i < n ;){
    cin >> res;
    
    if( res == "OUT" ){
      cnt++;
      if( cnt == 3 ){
	i++;
	cnt = 0;
	cout << point << endl;
	point = 0;
	cntH = 0;
      }
    }
    else if( res == "HIT" ){
      cntH++;
      if( cntH == 4 ){
	point++; cntH--;
      }
    }
    else{
      point += cntH+1;
      cntH = 0;
    }
      
      
      }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int ans[111], an,out, n,iti,ni,san;
	string a;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ans[i] = 0;
		iti = 0;
		out = 0;
		ni = 0;
		san = 0;
		while (1) {
			cin >> a;
			if (a == "HIT") {
				if (san == 1) {
					ans[i] = ans[i] + 1;
					san = 0;
				}
				if (ni == 1) {
					san = 1;
					ni = 0;
				}
				if (iti == 1) {
					ni = 1;
					iti = 0;
				}
				iti = 1;
			}
			if (a == "HOMERUN") {
				if (san == 1) {
					ans[i] = ans[i] + 1;
					san = 0;
				}
				if (ni == 1) {
					ans[i] = ans[i] + 1;
					ni = 0;
				}
				if (iti == 1) {
					ans[i] = ans[i] + 1;
					iti = 0;
				}
				ans[i] = ans[i] + 1;
			}
			if (a == "OUT") {
				out = out + 1;
				if (out == 3) {
					goto a;
				}
			}
		}
	a:;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
}