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>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<cstdio>
#include<climits>
#include<cfloat>
#include<cstring>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define rforeach(t,p) for(t::reverse_iterator it=p.rbegin();it!=p.rend();++it)
#define all(p) p.begin(),p.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define FOREACH(t,p,tit) for(t::iterator tit=p.begin();tit!=p.end();++tit)
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int lunner[3]={};
        int points = 0;
        int outs = 0;
        string ss;
        while(cin>>ss)
        {
            if(ss=="HOMERUN")
            {
                points++;
                rep(i,3){ if(lunner[i]==1){lunner[i]=0;points++;}}
                continue;
            }
            if(ss=="HIT")
            {
                if(lunner[2]==1){points++;continue;}
                if(lunner[1]==1){lunner[2]=1;continue;}
                if(lunner[0]==1){lunner[1]=1;continue;}
                if(lunner[0]==0){lunner[0]=1;continue;}
            }
            if(ss=="OUT"){outs++;}



            if(outs == 3)break;
        }
        cout << points << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
	int n; cin >> n ;
	int scoreA=0 ; int scoreB=0 ;
	for(int i=0;i<n;i++){
		int base=0; int out=0;string str; int score=0;
		while(1){
		cin >> str ;
		if(str=="OUT") out++;
		else if(str=="HIT") base++;
		else if(str=="HOMERUN") do{score+=++base; base=0;}while(0);
		if(out>=3) break;
		if(base>=4) do{base=3;score++;}while(0);
		};
		if(i%2==0) scoreA+=score; else scoreB+=score;
	};
	cout << scoreA << '\n' << scoreB << '\n' ;
}

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

int loop;
int runner,OUT,point;
string stait;

int main(){
  scanf("%d",&loop);
  for(int i=0;i<loop;i++){
    point = 0;
    OUT=0;
    runner=0;
      while(OUT<3){
	cin>>stait;
	if(stait=="HOMERUN"){
	  point += runner + 1;
	  runner = 0;
	}
	if(stait=="OUT"){
	  OUT++;
	}
	if(stait=="HIT"){
	  if(runner==3){
	    point++;
	  }else{
	    runner++;
   	  }
	}
      }
      printf("%d\n",point);
  }
}

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

int main()
{
	int n,inning=0;
	int p = 0, r = 0, o = 3;
	string event;

	cin >> n ;
	while (1)
	{
                        //r = ???????????????o = ??¢???????????°
		cin >> event;

		if (event == "HIT")
		{
			r++;
			if (r >= 4)                       //??????
			{
				p++;
                r=3;
			}
		}
		else if (event=="HORMRUN")
		{
			p += r + 1;
			r = 0;                            //??????????????????????????????
		}
		else if (event=="OUT")
		{
			o--;
			if (o == 0)
			{
				cout << p << endl;
				inning++;
				r = 0;
				o = 3;
				p = 0;
			}
		}

		if (n == inning) break;

	}

	return 0;
}

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

int base;

int hit(){
	if(base==3) return 1;
	else base++;
	return 0;
}

int homerun(){
	base++;
	return base;
}

int main(){
	int inning;
	std::cin >> inning;

	for(int i=0;i<inning;i++){
		int outCount=0;
		int point=0;
		std::string result;
		base=0;
		while(outCount<3){
			std::cin >> result;

			if(result == "HIT"){
				point += hit();
			} else if(result == "HOMERUN"){
				point += homerun();
				base=0;
			} else if(result == "OUT"){
				outCount++;
			}
		}
		std::cout << point << std::endl;
	}

    return 0;
}

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

void func()
{
	int point = 0;
	int out   = 0;
	int hit   = 0;
	string str;

	while(out < 3)
	{
		cin >> str;
		if(str == "OUT"    )
		{
			out++;
		}
		else if(str == "HOMERUN") 
		{
			point += hit+1;
			hit = 0;
		}
		else if(str == "HIT")
		{
			if(hit<3)	hit++;
			else		point++;
		}
	}
	cout << point << endl;
}


int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		func();
	}
	return 0;
}

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(){
	int n;
	cin>>n;
	string str;
	while(n--){
		int out = 3;
		int score = 0;
		int f,s,t;
		f=s=t=0;
		while(out){
			cin>>str;
			stringstream ss;
			ss <<str;
			string tmp;
			ss >>tmp;
			if(tmp=="HIT"){
				if(t){
					score++;
					t = 0;
				}
				if(s){
					s = 0;
					t = 1;
				}
				if(f){
					s = 1;
					f = 1;
				}else{
					f=1;
				}
			}else if(tmp=="HOMERUN"){
				//cout <<"tmp = "<<tmp<<endl;
				score+=(t+s+f+1);
				//cout <<score<<endl;
				t=s=f=0;
			}else{
				out--;
			}
		}
		cout <<score<<endl;
	}
	return 0;
}

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

int main() {
	int n, point[4], count;
	char str[50];

	while (cin >> n != NULL) {
		getchar();
		for (int i = 0; i < n; i++) {
			memset(point, 0, sizeof(point));
			count = 0;
			while (count != 3) {
				cin >> str;
				if (strcmp(str, "HIT") == 0) {
					for (int j = 2; j >= 0; j--) {
						if (point[j]) {
							point[j] = 0;
							point[j+1] += 1;
						}
					}
					point[0] = 1;
				} else if (strcmp(str, "OUT") == 0) {
					count++;
				} else if (strcmp(str, "HOMERUN") == 0) {
					int c = 0;
					for (int j = 0; j < 3; j++) {
						if (point[j])
							c++;
						point[j] = 0;
					}
					point[3] += c + 1;
				}
			}
			cout << point[3] << endl;
		}
	}

	return 0;
}

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

int main(){
    int hit, out, score, data_set_num;
    std::string event, str;
    std::getline(std::cin,str);
    sscanf(str.c_str(),"%d ",&data_set_num);

    while(data_set_num != 0){
        std::cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                hit = 3;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            score = 0;
            --data_set_num;
        }
    }

    return 0;
}