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>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  int out=0,b=0,p= 0;

  while(cin >> s){
    if(s == "OUT" && out == 2){
      out = 0;
      b = 0;
      n--;
      cout << p << endl;
      p = 0;
      //  if(n == 0)  break;
    } 
    if(s == "OUT") out++;
    if(s == "HIT"){
      if(b == 3 ) p++;
      else b++;
    }
    if(s == "HOMERUN"){
      p += b + 1;
      b = 0;
    }
  }

  return 0;
}

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

int main(){
    int n;
    cin >> n;
    while( n-- > 0 ){
        int out = 0, score = 0, base = 0;
        string event;
        while( out < 3 ){
            cin >> event;
            if( event == "OUT" ) out++;
            else if( event == "HIT" ){
                score += base/3;
                if( !(base/3) ) base++;
            }else if( event == "HOMERUN" ){
                score += base+1;
                base = 0;
            }
        }
        cout << score << endl;
    }
    return 0;
}

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

int base[3];
int point = 0;
int out = 0;
int n;

//イニング終わり
void reset_base() {
	for (int i = 0; i < 3; ++i) {
		base[i] = 0;
	}
}

//シングルヒット
void Single_hit() {
	point += base[2];
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
}

//ホームラン
void HomeRun() {
	for (int i = 0; i < 2; ++i) {
		point += base[i];
		base[i] = 0;
	}
	++point;
}

void Out() {
	++out;
	if (out == 3) {
		reset_base();
		out = 0;
		cout << point << endl;
		point = 0;
		--n;
	}
}


int main() {
	cin >> n;
	string s;
	while (n) {
		cin >> s;
		if (s == "HIT") {
			Single_hit();
		}
		else if (s == "HOMERUN") {
			HomeRun();
		}
		else if (s == "OUT") {
			Out();
		}
	}
}

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

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

    int score[n];
    for( int i = 0; i < n; i++ )
        score[i] = 0;
    
    int out = 0, inning = 0;
    bitset<4> b = 0;
    string event;

    while( cin >> event )
    {
        if( event == "HIT" )            //ヒット
        {
            b <<= 1;                    // <<=1は1ビット左にシフト
            b[0] = 1;                   // b[0]は000'0'を示す。b[1]は00'0'0を示す。

            if( b[3] == 1 )
            {
                score[inning]++;
                b[3] = 0;
            }
        }
        else if( event == "OUT" )       //アウト
        {
            out++;
            if( out == 3 )
            {
                inning++;
                out = 0;
                b = 0;
            }
        }
        else                            //ホームラン
        {
            score[inning] += b.count() + 1;
            b = 0;
        }
    }

    for( int i = 0; i < n; i++ )
        cout << score[i] << 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 << result << endl;
	}
}

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

int main(void)
{
  int n,a[40]={0},o,r,ct; //ctテ」ツ?ッテ」ツつ、テ」ツδ凝」ツδウテ」ツつーテヲツ閉ーテ」ツ?ョテァツョツ。テァツ青?
  string ivent;
  r=0;
  o=0;
  ct=0;
  
  cin >> n;
  while(1) { 
    cin >> ivent;
    if(ivent=="HIT") {
      r++;
      if(r>=4) {
	a[ct]++;
      } 
    } else if(ivent=="HOMERUN") {
      if(r<=3) { 
	a[ct]+=r+1;
      } else {
	a[ct]+=4;
      }
      r=0;

    } else if(ivent=="OUT") {
      o++;
      if(o==3) {
	ct++;
	o=0;
	r=0;      
      }  
    }
    if(ct==n) break;

  }

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

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

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

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT"){
				baseball.add_out();
			
				if(baseball.get_out() == 3)
					break;
				
			}
		}
	std::cout >> baseball.get_point() >> std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int main() {
    int n;
    cin >> n;
    int a = 0, out = 0;
    int base[4] = {0};
    string s;
    while (cin >> s) {
        if (s == "HIT") {
            for (int i = 2; i >= 0; i--) {
                if (base[i]) base[i+1] = 1, base[i] = 0;
            }
            base[0] = 1;
            if (base[3]) {
                a++;
                base[3] = 0;
            }
        }else if (s == "HOMERUN") {
            REP(i,3) a += base[i];
            a++;
            REP(i,3) base[i] = 0;
        }else {
            out++;
        }
        if (out == 3) {
            cout << a << endl;
            out = 0;
            a = 0;
            REP(i,4) base[i] = 0;
        }
    }
}

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

void simulate(){
	int outCount=0;
	int point=0;

	bool *base;
	base = new bool[4];
	for (int i=0;i<4;i++){
		base[i]=false;
	}

	string event;
	while(outCount!=3){
		cin >> event;


		if(event == "HIT"){
			if(base[3]){
				point++;
				base[3]=false;
			}
			if(base[2]){
				base[3]=true;
				base[2]=false;
			}
			if(base[1]){
				base[2]=true;
				base[1]=false;
			}
			base[1]=true;
		}

		else if(event == "HOMERUN"){
			for(int i=1;i<=3;i++){
				if(base[i]){
					point++;
					base[i]=false;
				}
			}
			point++;
		}

		else if(event == "OUT"){
			outCount++;
		}

		else{
			cout << "undefined" << endl;
			exit(1);
		}

	}

	cout << point << endl;
}

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

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

	return 0;
}