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++: &#65279;&#65279;#include <iostream>
#include <string>
using namespace std;

int main(void)
{
  int point;
  int single_hit;
  int out;
  int inning;
  string event;

  cin >> inning;

  for(int i = 0 ; i < inning ; i++)
    {
      point = 0;
      out = 0;
      single_hit = 0;

      while(1)
	{
	  if(out == 3) break;
	  
	  cin >> event;
	  if(event == "HIT") single_hit++;	  
	  if(event == "OUT") out++;
	  if(event == "HOMERUN") 
	    {
	      point += (single_hit + 1);
		/*if(single_hit == 1) point+=2;
	      if(single_hit == 2) point+=3;
	      if(single_hit == 3) point+=4;*/
	      single_hit = 0;
	    }
	  if(single_hit == 4)
	    {
	      point++;
	      single_hit--;
	    }
	}
      cout << point << endl;
    }
  return 0;
}

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

int main(){
	int inning;
	int i, out = 0, hit = 0;
	int score = 0;
	char event[8];
	
	scanf("%d", &inning);
	
	while(inning != 0){
		scanf("%s", event);
		if(!strcmp(event, "HOMERUN")){
			score += hit + 1;
			hit = 0;
		}else if(!strcmp(event, "HIT")){
			hit++;
			if(hit == 4){
				score++;
				hit--;
			}
		}else if(!strcmp(event, "OUT")){
			out++;
		}
 		if(out == 3){
			inning--;
			out = 0;
			hit = 0;
			cout << score << endl;
			score = 0;
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	int n;
	cin >> n;
	string S;
	rep(i,n){
		int OUT = 0;
		int mnd = 0;
		int score = 0;
		while(OUT != 3){
			cin >> S;
			if(S == "OUT")OUT++;
			if(S == "HIT"){
				mnd++;
				if(mnd > 3){
					mnd--;
					score++;
				}
			}
			if(S == "HOMERUN"){
				score += mnd+1;
				mnd = 0;
			}
		}
		FIN(score);

	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
	int n,ans;
	int out;
	bool runner[3];
	string s;
	cin>>n;
	for(int i=0;i<n;i++){
		ans=0;
		out=0;
		memset(runner,false,sizeof(runner));
		while(out<3){
			cin>>s;
			if(s=="OUT")out++;
			if(s=="HIT"){
				if(runner[2]){
					ans++;
					runner[2]=false;
				}
				if(runner[1]){
					runner[2]=true;
					runner[1]=false;
				}
				if(runner[0])runner[1]=true;
				runner[0]=true;
			}
			if(s=="HOMERUN"){
				ans++;
				for(int i=0;i<3;i++){
					if(runner[i]){
						ans++;
						runner[i]=false;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}

C++: /*
	0103:Baseball Simulation
*/
#include	<iostream>
#include	<string>

using namespace std;

int main(void) {
	int d;
	
	cin >> d;
	
	while(d-- > 0) {
		int point = 0, outcount = 0;
		int firstBase = 0, secondBase = 0, thirdBase = 0;
		string event;
		while(outcount < 3) {
			cin >> event;
			if(event == "OUT") {
				outcount++;
			} else if(event == "HOMERUN") {
				point += firstBase + secondBase + thirdBase + 1;
				firstBase = 0;
				secondBase = 0;
				thirdBase = 0;
			} else {
				point += thirdBase;
				thirdBase = secondBase;
				secondBase = firstBase;
				firstBase = 1;
			}
		}
		cout << point << endl;
	}
	
	return 0;
}

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

int main()
{
	int n,inning=0;
	int inningp[34];
	string ivent;

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

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

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)                       //?????? = ???????????? + ????????????(1???)
				{
					p += 4;
				}
				else
				{
					p += r + 1;
				}
				r = 0;                            //??????????????????????????????
			}
			else
			{
				o--;
			}
		}

		inningp[inning] = p;                      
		inning++;

	}

	for (int i = 0; i < inning; i++)
	{
		cout << inningp[i] << endl;
	}

	return 0;
}

C++: #include <string>
#include <iostream>
using namespace std;
int N, c1, c2, c3, out, ret; string S;
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		c1 = 0, c2 = 0, c3 = 0, out = 0, ret = 0;
		while (out != 3) {
			cin >> S;
			if (S == "HIT") {
				ret += c3, c3 = c2, c2 = c1, c1 = 1;
			}
			else if (S == "HOMERUN") {
				ret += c1 + c2 + c3;
			}
			else {
				out++;
			}
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int cnt = 0;
	REP(j, n) {
		int out = 0, score = 0;
		vi v(3, 0);
		while (out <3) {
			string s;
			if (cin >> s)cnt++;
			
			if (s == "HIT") {
				RREP(i, 3) {
					if (v[i] == 1) {
						if (i == 2)score++;
						else v[i + 1]++;
						v[i]--;

					}
				}
				v[0]++;
			}
			else if (s[0] == 'O') {
				out++;
			}
			else {
				REP(i, 3) {
					if (v[i] == 1) {
						score++;
						v[i] = 0;
					}
				}
				score++;
			}
			assert(cnt <= 100);
		}
		cout << score << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  string event;
  getline(cin,event,'\n');
  int i=0,out,b,score;
  while(n>0){
    out = 0;
    b = 0;
    score=0;
    while(out<3){
      getline(cin,event,'\n');
      if(event=="HIT"){
	b*=2;
	b+=1;
	if(b>8){
	  b-=8;
	  score++;
	}
      }
      if(event=="HOMERUN"){
	while(b>0){
	  score+=b%2;
	  b/=2;
	}
	score++;
      }
      if(event=="OUT"){
	out++;
      }
    }
    cout<<score<<endl;
    n--;
  }
  return 0;
}