Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

C++: #include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,i,j,k;
  cin>>n;
  rep(i,n){
    int out=0;
    int score=0;
    bool first=false;
    bool second=false;
    bool third=false;

    while(1){
      cin>>str;
      if(str=="OUT"){
	out++;
	if(out==3)break;
      }
      if(str=="HIT"){
	if(first){
	  if(second){
	    if(third)
	      score++;
	    else
	      third=true;
	  }
	  else
	    second=true;
	}
	else
	  first=true;
      }
      if(str=="HOMERUN"){
	score++;
	if(first){
	  first=false;
	  score++;
	}
	if(second){
	  second=false;
	  score++;
	}
	if(third){
	  third=false;
	  score++;
	}
      }
    }	

    cout<<score<<endl;
  }
}

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

int count8bit( unsigned char v ){
	unsigned int count = ( v & 0x55 ) + ( ( v >> 1 ) & 0x55 );
	count = ( count & 0x33 ) + ( ( count >> 2 ) & 0x33 );
	return ( count & 0x0f ) + ( ( count >> 4 ) & 0x0f );
}

int main()
{
	int n;

	cin >> n;

	for( int inning_cnt = 0; inning_cnt < n; ++inning_cnt ){
		int point = 0;
		int out_cnt = 0;
		unsigned char base = 0;
		while( out_cnt < 3 ){
			base |= 1;
			string s;
			cin >> s;
			if( s == "HIT" ){
				base <<= 1;
				if( base & 1 << 4 ){
					base -= ( 1 << 4 );
					++point;
				}
			}else if( s == "HOMERUN" ){
				point += count8bit( base );
				base = 0;
			}else if( s == "OUT" ){
				++out_cnt;
			}
		}
		cout << point << 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){
					std::cout >> baseball.get_point() >> std::endl;
					break;
				}
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N;
	cin>>N;
	while(N--){
		int out=0,fld[4]={},score=0;
		string S;
		while(out<3){
			cin>>S;
			if(S=="HIT"){
				for(int i=3;i>=0;i--) fld[(i+1)%4] = fld[i];
				fld[1] = 1;
				score += fld[0]; fld[0] = 0;
			}
			else if(S=="HOMERUN"){
				fld[0] = 1;
				for(int i=0;i<=3;i++){
					score += fld[i];
					fld[i] = 0;
				}
			}
			else out++;
		}
		printf("%d\n",score);
	}
    return 0;
}

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


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

    int base[4]={0};
    int score=0;
    int out=0;
    char s[100];
    while(scanf("%s",s,stdin)!=EOF){
        if(strcmp(s,"HIT")==0){
            score+=base[3];
            base[3]=base[2];
            base[2]=base[1];
            base[1]=1;
        }
        if(strcmp(s,"HOMERUN")==0){
            score+=(base[3]+base[2]+base[1]+1);
            base[1]=0;
            base[2]=0;
            base[3]=0;
        }
        if(strcmp(s,"OUT")==0){
            out+=1;
            if(out==3){
                out=0;
                base[1]=0;
                base[2]=0;
                base[3]=0;
                cout<<score<<endl;
                score=0;
            }
        }
    }
    return 0;
}

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

int main()
{
	std::string innings;
	getline(std::cin, innings);
	int bInnings = std::stoi(innings);
	
	int outs = 0;
	int score = 0;
	int base[3] = {0, 0, 0};
	for (int i=0; i<bInnings; ) {
		std::string event;
		getline(std::cin, event);
		if (event == "HIT") {
			if (base[2] == 1) score++;
			base[2] = base[1];
			base[1] = base[0];
			base[0] = 1;
		}
		else if (event == "HOMERUN") {
			score += base[0] + base[1] + base[2] + 1;
			base[0] = base[1] = base[2] = 0;
		}
		else {
			outs++;
			if (outs == 3) {
				std::cout << score << std::endl;
				score = 0;
				base[0] = base[1] = base[2] = 0;
				outs = 0;
				i++;
			}
		}
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
int main(){
	int n; cin>>n;
	while(n--){
		int c = 0,hit = 0,p = 0;
		while(c != 3){
			string s; cin>>s;
			if(s == "HIT"){
				if(hit == 3) p++;
				else hit++;
			} else if(s == "OUT"){
				c++;
			} else {
				p += hit + 1;
				hit = 0;
			}
		}
		cout << p << endl;
	}
    return 0;
}

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

int main() {
　　　int e;
　　　cin >> e;
　　　for(int i=0;i<e;i++){
　　　　　　int o=0,r=0,c=0;
　　　　　　while(1){
　　　　　　　　　string str;
　　　　　　　　　if(o==3) break;
　　　　　　　　　cin >> str;
　　　　　　　　　if(str=="HIT"){
　　　　　　　　　　　　if(r==3) c++,r--;
　　　　　　　　　　　　r++;
　　　　　　　　　}
　　　　　　　　　else if(str=="OUT") o++;
　　　　　　　　　else{
　　　　　　　　　　　　c+=r+1;
　　　　　　　　　　　　r=0;
　　　　　　　　　}
　　　}
　　　cout << c << endl;
　　　}
}

C++: //0103
#include<string.h>
#include<stdio.h>
int main()
{
	int n,op,f,se,t,r;
	char s[16];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		r=0;
		op=0;
		f=0;
		se=0;
		t=0;

		while(op<3){
			scanf("%s",s);
			if(strcmp("OUT",s)==0){
				op++;
			}else if(strcmp("HIT",s)){
				r+=t;
				t=se;
				se=f;
				f++;
			}else{
				r+=(f+se+t+1);
				f=se=t=0;
			}
		}
		printf("%d\n",r-3);
	}
	return 0;
}

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

main(){
  int i,j,n,b1,b2,b3,run,score,out;
  string str;
  cin >> n;

  for(i=0;i<n;i++){
    b1 = b2 = b3 = score = out = run = 0;

    while(out < 3){
      cin >> str;
      if(str == "OUT") out++;
      else if(str == "HIT"){
	if(b1 == 0){
	  b1 = 1;
	  run++;
	}
	else if(b2 == 0){
	  b2 = 1;
	  run++;
	}
	else if(b3 == 0){
	  b3 = 1;
	  run++;
	}
	else score++;
      }
      else if(str == "HOMERUN"){
	score += run + 1;
	b1 = b2 = b3 = run = 0;
      }
    }

    cout << score << endl;
  }
  return 0;
}