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<string>
#include<iostream>

using namespace std;

int main()
{
	int n;	cin>>n;
	string s;
	int runner=0,out=0,score=0;
	while(cin>>s){
		if(s=="HIT"){
			runner<<=1;
			if(runner&8)runner&=~8,score++;
			runner|=1;
		}
		else if(s=="HOMERUN"){
			for(int i=0;i<3;i++){
				runner<<=1;
				if(runner&8)runner&=~8,score++;
			}
			score++;
		}
		else{
			out++;
			if(out==3)	cout<<score<<endl,runner=out=score=0;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	cin >> n;
	int times = 0;
	int hit = 0;
	int point = 0;
	int out= 0 ;
	for(;times<n;){
		string s;
		cin >> s;
		if(s=="OUT"){
			out++;
			if(out==3){
				times++;
				cout << point << "\n";
				hit = 0;
				point = 0;
				out = 0;
			}
		}else if(s=="HIT"){
			if(hit<3) hit++;
			else point++;
		}else if(s=="HOMERUN"){
			point += hit+1;
			hit = 0;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
using namespace std;
 
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0103 

int main() {
	int n;
	cin >> n;
	for (int k = 0; k < n; k++) {
		queue<int> q;
		int ans = 0;
		int out = 0;
		while (true) {
			string s;
			cin >> s;
			if (s == "HIT") {
				q.push(1);
				if (q.size() > 3) {
					ans++;
					q.pop();
				}
			} else if (s == "HOMERUN") {
				while (q.size() > 0) {
					if (q.front() == 1) ans++;
					q.pop();
				}
				ans++;
			} else {
				out++;
				if (out == 3) break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;




int main()
{
	int n;
	string event;
	int out;
	int rui[4];
	int tokuten;
	
	cin >> n;
	for (int i=0; i<n; i++)
	{
		out = 0;
		tokuten = 0;
		for (int j=0; j<4; j++) rui[j] = 0;
		while (cin >> event)
		{
			if (event == "HIT")
			{
				rui[3] = rui[2];
				rui[2] = rui[1];
				rui[1] = rui[0];
				rui[0] = 1;
				tokuten += rui[3];
				rui[3] = 0;
			} else if (event == "HOMERUN") {
				tokuten += rui[0] + rui[1] + rui[2] + 1;
				rui[0] = rui[1] = rui[2] = 0;
			} else if (event == "OUT") {
				out += 1;
				if (out == 3)
				{
					cout << tokuten << endl;
					break;
				}
			}
		}
	}
	
	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;m=0;
}
return 0;
}

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

class Game{
	int flag;
	int point;
	int out;
	int count;
	char sta[10];

public:
	int IN(const char *);
	int OUT();
	void Reset();
};

int Game::IN(const char *str){
	if(strcmp("HIT",str) == 0){
		if(count < 3)count++;
		else point++;
	}
	else if(strcmp("HOMERUN",str) == 0){
		point += count + 1;
		count = 0;
	}
	else{
		out++;
		if(out >= 3){
			flag++;
			return flag;
		}
	}
	return 0;
}

int Game::OUT(){
	return point;
}
void Game::Reset(){
	flag = 0;
	point = 0;
	out = 0;
	count = 0;
}


int main(){
	int i,f,set = 0;
	int po[50];
	char sta[10];
	Game ini;

	cin >> set;

	for(i = 0; i < set; i++ ){
		ini.Reset();
		f = 0;
		while(1){
			cin >> sta;
			f = ini.IN(sta);
			if(f == 1)break;
		}
		po[i] = ini.OUT();

	}

	for(i = 0; i < set ; i++)
		cout << po[i] << endl;

	return 0;
}

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

using namespace std;

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

  while(n){
    string s;
    int hit=0,out=0,point=0;
    while(1){
      cin >> s;
      if(s == "HIT"){
        hit++;
        if(hit > 3) point++,hit=3;
      }
      if(s == "HOMERUN"){
        point += hit+1;hit=0;
      }
      if(s == "OUT"){
        out++;
        if(out == 3) break;
      }
    }
    cout << point << endl;
    n--;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
int main(){
	int n,m=0,n2=0,s1=0,s2=0;
	std::cin>>n;
	int o=0;
	while(n>m){
		std::string str;
		std::cin>>str;
		std::vector<int> vec(3);
		if(str=="HIT"&&n2%2==0){
			if(vec[2]==1)s1++;
			else if(vec[0]==1){
				if(vec[1]==1)vec[0]=0,vec[2]=1;
				else vec[0]=0,vec[1]=1;
			}else if(vec[1]==1){
				vec[1]=0,vec[2]=1;
			}
		}
		if(str=="HIT"&&n2%2==1){
			if(vec[2]==1)s2++;
			else if(vec[0]==1){
				if(vec[1]==1)vec[0]=0,vec[2]=1;
				else vec[0]=0,vec[1]=1;
			}else if(vec[1]==1){
				vec[1]=0,vec[2]=1;
			}
		}
		if(str=="HOMERUN"&&n2%2==0){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s1++;
			}
			s1++;
		}
		if(str=="HOMERUN"&&n2%2==1){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s2++;
			}
			s2++;
		}
		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,n2++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	std::cout<<s1<<std::endl<<s2<<std::endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >> n;
    vector<string> a(101);
    bool run[3]={false, false, false};
    int out=0, e=0;
    int point[50];
    int j=0;
    int k=0;
    while(cin >> a[j]) {
        if(a[j]=="HIT") {
            if(run[2]) {
                point[e]++;
                run[2] = false;
            }
            if(run[1]) {
                run[2] = true;
                run[1] = false;
            }
            if(run[0]) {
                run[1] = true;
                run[0] = false;
            }
            run[0] = true;
        } else if(a[j]=="OUT") {
            out++;
            if(out==3) {
                out = 0;
                run[0] = false;
                run[1] = false;
                run[2] = false;
                e++;
            }
        } else {
            k=0;
            if(run[0]) k++;
            if(run[1]) k++;
            if(run[2]) k++;
            run[0] = false;
            run[1] = false;
            run[2] = false;
            REP(i,k) {
                point[e]++;
            }
            point[e]++;
        }
        j++;
    }
    REP(i,n) {
        cout << point[i] << endl;
    }

}

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

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int p = 0;
		int oc = 0;
		int rui[4] = {1,0,0,0};
		while(1){
			string s;
			getline(cin,s);
			if(s=="OUT") oc++;
			else if(s=="HIT"){
				if(rui[3]==1) p++;
				for(int j=3;j>0;j--) rui[j] = rui[j-1];
			}
			else if(s=="HOMERUN"){
				for(int j=1;j<4;j++){
					if(rui[j]==1) p++;
					rui[j] = 0;
				}
					p++;
			}
			if(oc==3) break;
		}
		cout << p << endl;
	}
}