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>
#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;
	}
}

C++: #include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		char c[10];
		int sum=0,people=0,out=0;
		while(out<3){
			scanf("%s",c);
			if(c[1]=='I'){
				people++;
				if(people==4){
					sum+=1;
					people=3;}}
			if(c[1]=='O'){
				sum+=people+1;
				people=0;}
			if(c[1]=='U'){
				out++;}}
		printf("%d\n",sum);}
	return 0;}

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

int main(){

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

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int ini = 0, out = 0, hit = 0, cnt = 0  ;
  while (ini <= n) {
    string s;
    cin >> s;
    if (s == "OUT") {
      out++;
      if (out == 3) {
        cout << cnt << endl;
        cnt = 0;
        hit = 0;
        out = 0;
        ini++;
      }
    }
    if (s == "HIT") {
      if (hit == 3) {
        cnt++;
      } else {
        hit++;
      }
    }

    if (s == "HOMERUN") {
      cnt += hit + 1;
      hit = 0;
    }
  }

}

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

using namespace std;

int main() {
	int base = 0;
	int out = 0;
	int score = 0;
	int inning;
	string evt;
	cin >> inning;
	while (inning) {
		cin >> evt;
		if (evt == "HIT") {
			base <<= 1;
			base |= 1;
			if (base > 7) {
				score++;
				base &= 7;
			}
		} else if (evt == "HOMERUN") {
			score++;
			for (int i = 0; i < 4; i++) {
				if ((base >> i) & 1) {
					score++;
				}
			}
			base = 0;
		} else {
			if (++out >= 3) {
				cout << score << endl;
				base = score = out = 0;
				inning--;
			}
		}
	}
	return 0;
}

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

int main(){
  int n,ansc=0,count=0,count1=0,count2=0,count3=0;
  string event[100];
  cin>>n;
  int i=0;
  while(1){
    cin>>event[i];
    if(event[i]=="OUT"){
      count++;
      count3++;
    }
    if(event[i]=="HIT")count1++;
    if(event[i]=="HOMERUN")count2++;
    if(count3==3*n)break;

    if(count==3){
      count=0;
      count1=0;
      count2=0;
    }
    else if(count2==1){
      ansc+=count1+1;
      count1=0;
      count2=0;
    }
    else if(count1==4){
      ansc++;
      count1--;
    }
    i++;
  }
    cout<<ansc<<endl;
  return 0;
}