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>
 
class Baseball
{
    u_int runner, out, point;
     
public:
    Baseball();
    ~Baseball(){}
         
    u_int get_out() const {return out;}
    u_int get_point() const {return point;}
    
    void game();
    void event_hit();
    void event_homerun();
    void event_out();
     
private:
    void set_runner(const u_int r) {runner = r;}
    void inc_runner() {++runner;}
    void inc_out() {++out;}
    void add_point(const u_int p) {point += p;}
};
 
Baseball::Baseball()
{
    runner = 0;
    out = 0;
    point = 0;
}

void Baseball::game()
{
    std::string event;
    while(get_out() != 3){
        std::cin >> event;
        if(event == "HIT"){
            event_hit();
        }
        else if(event == "HOMERUN"){
            event_homerun();
        }
        else{
            event_out();
        }
    }
} 

void Baseball::event_hit()
{
    if(get_runner() == 3){
        add_point(1);
    }
    else{
        inc_runner();
    }   
}
 
void Baseball::event_homerun()
{
    add_point(1 + get_runner());
    set_runner(0);
}
 
void Baseball::event_out()
{
    inc_out();
}
 
int main()
{
    u_int inning;
    std::cin >> inning;
     
    for(u_int i = 0; i < inning; ++i){
        Baseball b_ball;
        b_ball.game();
        std::cout << b_ball.get_point() << std::endl;
    }
 
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int solve(){
  int base=0,out=0,point=0;
  string key;
  while(out!=3){
    cin>>key;
    if(key=="HIT"){
      if(base&1<<2)point++;
      base<<=1;base++;
    }else if(key=="HOMERUN"){
      point++;
      for(int j=0;j<3;j++)if(base&1<<j)point++;
      base=0;
    }else if(key=="OUT")out++;
  }
  return point;
}
int main(){
  int a;
  cin>>a;
  for(int i=0;i<a;i++)cout<<solve()<<endl;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;



int main(){

	char buf[30];
	int n,sum,runner_num,out_count;

	scanf("%d",&n);

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

		sum = 0,runner_num = 0,out_count=0;

		while(out_count < 3){
			scanf("%s",buf);

			switch(buf[1]){
			case 'I':
				runner_num++;
				if(runner_num == 4){
					sum += 1;
					runner_num = 3;
				}
				break;
			case 'O':
				sum += runner_num + 1;
				runner_num = 0;
				break;
			case 'U':
				out_count++;
				break;
			}
		}
		printf("%d\n",sum);
	}
    return 0;
}

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

int main(void) {
  int n;
  string event;

  cin >> n;
  while(n--) {
    int out = 3;
    int ret = 0;
    int runner = 0;
    
    while(out) {
      cin >> event;
      if(event == "HIT") runner++;
      if(event == "OUT") out--;
      if(event == "HOMERUN") {
	ret+=(runner+1);
	runner=0;
      }
      if(runner==4) { runner--; ret++; }
    }
    cout << ret << endl;
  }

  return 0;
}

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

int type(string s){
	if(s == "HIT")return 0;
	if(s == "OUT")return 1;
	if(s == "HOMERUN")return 2;
}
int main(){
	int n;
	string s;
	cin >> n;
	
	while(n--){
		int outCount = 0;
		int base = 0;
		int result = 0;
		while(outCount < 3){
			cin >> s;
			switch(type(s)){
			case 0:
				base <<= 1;
				base++;
				break;
			case 1:
				outCount++;
				break;
			case 2:
				result += __builtin_popcount(base)+1;
				base = 0;
				break;
			}
			if(base & 8)result++;
			base &= 7; // 0b0111
			cout << s << base << endl;
		}
		cout << result << endl;
	}
}

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

class Baseball{
	private:
	int out;
	int runner;
	int point;

	public:
	void init();
	int get_out();
	int get_point();
	void event_hit();
	void event_homerun();
	void event_out();
};

void Baseball::init(){
	out = 0;
	runner = 0;
	point = 0;
}

int Baseball::get_out(){
	return out;	
}

int Baseball::get_point(){
	return point;
}

void Baseball::event_hit(){
	if(runner == 3){
		++point;
	}else{
		++runner;
	}
}

void Baseball::event_homerun(){
	point += ++runner;
	runner = 0;
}

void Baseball::event_out(){
	++out;
}

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	Baseball base;
	base.init();
	for(int i = 0; i < num; ++i){
		while(base.get_out() < 3){
			std:: cin >> event;

			if(event == "OUT"){
				base.event_out();		
			}else if(event == "HIT"){
				base.event_hit();
			}else if(event == "HOMERUN"){
				base.event_homerun();
			}
		}
		std::cout << base.get_point() << std::endl;
		base.init();
	}
	return 0;
}

C++: #include<stdio.h>

int main(){
	int c,y,t,o,p;
	char a[9];
	read(0,c,4);
	for(y=0;;y++){
		for(t=o=p=0;;){
			if(!~scanf("%s",a))return 0;
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}
}

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

int n;
char event[8];

int main(){
  scanf("%d",&n);
  int point,outcnt;
  for(int i=0;i<n;i++){
    int base[3]={0};
    point=0;
    outcnt=0;
    while(outcnt<3){
      scanf(" %s",event);
      if(strcmp(event,"HIT")==0){
	if(base[2]==1){base[2]=0;point++;}
	if(base[1]==1){base[1]=0;base[2]=1;}
	if(base[0]==1){base[1]=1;}
	base[0]=1;
      }
      if(strcmp(event,"HOMERUN")==0){
	for(int i=2;i>=0;i--)if(base[i]==1){base[i]=0;point++;}
	point++;
      }
      if(strcmp(event,"OUT")==0)outcnt++;
    }
    printf("%d\n",point);
  }
}

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

int main(){
  int n,ansc=0,o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;

  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;
    if(o2==3*n)break;

    if(h==4){
      ansc++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
    }
    else if(hr==1){
      ansc+=h+1;
      h=0;
      hr=0;
    }
  }
  i++;
  cout<<ansc<<endl;
return 0;
}

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

int main(void) {
    u_int n;
    std::string event;

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        // 各ビットがそれぞれの塁のランナーの有無を表現する
        std::bitset<4> runner;
        u_int out = 0, score = 0;

        do {
            std::cin >> event;
            if ("HIT" == event) {
                runner <<= 1;   // ランナーを1つずつ進める
                runner.set(0);  // 一塁にランナーを置く
                // ホームインしたかどうか
                if (runner.test(3)) {
                    ++score;
                    runner.reset(3);
                }
            } else if ("HOMERUN" == event) {
                score += runner.count() + 1;
                runner.reset(); // ランナーをリセット
            } else if ("OUT" == event) {
                ++out;
            }
        } while (out != 3);

        std::cout << score << std::endl;
    }

    return 0;
}

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

int main(){
int N,m=0,rn=0,pn=0;
string str;
cin>>N;
for(int i=0;i<N;i++)
{
while(1){
cin>>str;
if(str=="OUT"){m++;
if(m==3)break;}
if(str=="HIT"){rn++;
if(rn==4){pn++;rn=3;}}
if(str=="HOMERUN"){
pn+=rn+1;rn=0;}
}
cout<<pn<<endl;
rn=0;pn=0;
}
return 0;
}