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>
using namespace std;
int main()
{
	int out = 0;
	int r1 = 0;
	int r2 = 0;
	int r3 = 0;
	int t = 0;
	int t1 = 0;
	string k;
	int a = 0;
	cin >> a;
	for (int i = 1; i <= (2 * a); i++)
	{
		out = 0;
		r1 = 0;
		r2 = 0;
		r3 = 0;
		while (out != 3)
		{
			cin >> k;
			if (k == "OUT")
			{
				out++;
			}
			if (k == "HIT")
			{
				if (r3 == 1)
				{
					if (i % 2 == 1)
					{
						t++;
					}
					else
					{
						t1++;
					}
					r3 = 0;
				}
				if (r2 == 1)
				{
					r3 = 1;
					r2 = 0;
				}
				if (r1 == 1)
				{
					r2 = 1;
					r1 = 0;
				}
			}
			if (k == "HOMERUN")
			{
				if (r3 == 1)
				{
					if (i % 2 == 1)
					{
						t++;
					}
					else
					{
						t1++;
					}
					r3 = 0;
				}
				if (r2 == 1)
				{
					if (i % 2 == 1)
					{
						t++;
					}
					else
					{
						t1++;
					}
					r2 = 0;
				}
				if (r1 == 1)
				{
					if (i % 2 == 1)
					{
						t++;
					}
					else
					{
						t1++;
					}
					r1 = 0;
				}
				if (i % 2 == 1)
				{
					t++;
				}
				else
				{
					t1++;
				}

			}
		}
	}
	cout << t << endl << t1 << endl;
	
	return 0;
}

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

int main() {

  int inning;
  char result[50];

  int base[3];
  int out;
  int point;

  int i,j;
  char c;

  scanf("%d",&inning);
  c=getchar();
  
  for(i=0;i<inning;i++) {
    
    for(j=0;j<3;j++) base[j]=0;
    //printf("%d %d %d\n",base[0],base[1],base[2]);
    out=0;
    
    point=0;

    while(1) {

      fgets(result,sizeof(result),stdin);

      result[strlen(result)-1]='\0';

      if(strcmp(result,"OUT")==0) {
	out++;
      }

      if(strcmp(result,"HOMERUN")==0) {
	
	for(j=0;j<3;j++) {
	  if(base[j]==1) point++;
	  base[j]=0;
	}

	point++;
      }

      if(strcmp(result,"HIT")==0) {
	
	if(base[2]==1) point++;

	for(j=0;j<3;j++) {
	  if(base[j]==0) {
	    base[j]=1;
	    break;
	  }
	}
      }
      //printf("%d %d %d %d %d\n",out,point,base[0],base[1],base[2]);
      if(out==3) break;

    }

  }

  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++;
					base--;
				}
			}else if(n == "OUT"){
				out++;
			}else if(n == "HOMERUN"){
				point += base + 1;
				base = 0;
			}
		}
		cout << point << 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 score = 0;
    int out = 0;

    int first = 0;
    int second = 0;
    int third = 0;

    while(1) {
      string str;
      cin >> str;
      if(str == "HIT") {
	score += third;
	third = second;
	second = first;
	first = 1;
      } else if(str == "HOMERUN") {
	score += first + second + third + 1;
	first = second = third = 0;
      } else if(str == "OUT") {
	out++;
      }

      if(out == 3) {
	cout << score << endl;
	break;
      }
    }
  }
  return 0;
}

C++: //Name: Baseball Simulation
//Level: 1
//Category: やるだけ
//Note:

/**
 * 仕様のとおりに実装する。
 *
 * オーダーは O(E)。
 * ただし、Eはイベントの個数。
 */
#include <iostream>
#include <string>

using namespace std;

bool solve() {
    int out = 0;
    int b1 = 0, b2 = 0, b3 = 0;
    int score = 0;
    while(out < 3) {
        string event;
        cin >> event;
        if(event == "HIT") {
            if(b3) ++score;
            b3 = b2; b2= b1; b1 = 1;
        } else if(event == "HOMERUN") {
            score = b1+b2+b3+1;
            b1 = b2 = b3 = 0;
        } else if(event == "OUT") {
            ++out;
        }
    }
    cout << score << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}

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

int main(){
   int a[4];
   int score,n;
   int out = 0;
   string in;
   cin >> n;
   for(int i=0;i<n;i++){
      a[3] = a[2] = a[1] = a[0] = 0;
      out   = 0;
      score = 0;
      while(out!=3){
	 cin >> in;
	 if(in ==  "HIT"){
	    a[3] = a[2];
	    a[2] = a[1];
	    a[1] = a[0];
	    a[0] = 1;
	    if(a[3] == 1){
	       score++;
	       a[3] = 0;
	    }
	 }
	 else if(in == "HOMERUN"){
	    score += a[2]+a[1]+a[0]+1;
	    a[2] = a[1] = a[0] = 0;
	 }
	 else if(in ==  "OUT"){
	    out++;
	 }
      }
      cout << score << endl;
   }
   return 0;
}

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

using namespace std;

int main(){
  int n;
  cin>>n;
  int point[33];
  int out[33];
  for(int i=0;i<33;i++){
    point[i]=0;
    out[i]=0;
  }
  int first=0;
  int second=0;
  int third=0;
  int number=0;
  char input[10];
  for(int i=0;i<n;i++){
    while(out[i]<3){
      cin>>input;
      if(strcmp(input,"HIT")==0){
	if(third==1){
	  point[i]++;
	}
	if(second==1){
	  third=1;
	}
	if(first==1){
	  second=1;
	}
	first=1;
      }
      if(strcmp(input,"HOMERUN")==0){
	int number=0;
	if(first==1){
	  number++;
	}
	if(second==1){
	  number++;
	}
	if(third==1){
	  number++;
	}
	point[i]+=(number+1);
	first=0;second=0;third=0;
      }
      if(strcmp(input,"OUT")==0){
	out[i]++;
      }
      if(out[i]==3){
	first=0;second=0;third=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<point[i]<<"\n";
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int out = 0;
	int r1 = 0;
	int r2 = 0;
	int r3 = 0;
	int t = 0;
	string k;
	int a = 0;
	cin >> a;
	for (int i = 1; i <= a; i++)
	{
		out = 0;
		r1 = 0;
		r2 = 0;
		r3 = 0;
		while (out != 3)
		{
			cin >> k;
			if (k == "OUT")
			{
				out++;
			}
			if (k == "HIT")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					r3 = 1;
					r2 = 0;
				}
				if (r1 == 1)
				{
					r2 = 1;
					r1 = 0;
				}
			}
			if (k == "HOMERUN")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					t++;
					r2 = 0;
				}
				if (r1 == 1)
				{
					t++;
					r1 = 0;
				}
				t++;

			}
		}
		cout << t << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int point;
	bool isRunner[3];
	int out;
	int n;
	char event[8];

	n = in();
	loop(i, 0, n)
	{
		point = 0;
		out = 0;
		isRunner[0] = isRunner[1] = isRunner[2] = false;

		while( out < 3 )
		{
			scanf("%s", event);
			switch( event[1] )
			{
				case 'I':
					if( isRunner[2] )
					{
						point++;
					}
					isRunner[2] = isRunner[1];
					isRunner[1] = isRunner[0];
					isRunner[0] = true;
					break;
				case 'O':
					point++;
					if( isRunner[0] )
					{
						point++;
					}
					isRunner[0] = false;
					if( isRunner[1] )
					{
						point++;
					}
					isRunner[1] = false;
					if( isRunner[2] )
					{
						point++;
					}
					isRunner[2] = false;
					break;
				case 'U':
					out++;
					break;
			}
		}
		printf("%d\n", point);
	}

	return (0);
}