Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)
const (
	allb = "bbb"
	allw = "www"
)

func main() {
	for scanner.Scan() {
		row1 := scanner.Text()
		if row1 == "0" {
			break
		}
		scanner.Scan()
		row2 := scanner.Text()
		scanner.Scan()
		row3 := scanner.Text()
		x := make([]string, 8)
		x[0] = row1
		x[1] = row2
		x[2] = row3
		for i := 0; i < 3; i++ {
			col := make([]string, 3)
			col[0] = string(row1[i])
			col[1] = string(row2[i])
			col[2] = string(row3[i])
			x[i+3] = strings.Join(col, "")
		}
		tmp := make([]string, 3)
		tmp[0] = string(row1[0])
		tmp[1] = string(row2[1])
		tmp[2] = string(row3[2])
		x[6] = strings.Join(tmp, "")
		tmp[0] = string(row1[2])
		tmp[1] = string(row2[1])
		tmp[2] = string(row3[0])
		x[7] = strings.Join(tmp, "")
		flag := false
		for _, v := range x {
			if string(v) == allb {
				fmt.Println("b")
				flag = true
				break
			} else if string(v) == allw {
				fmt.Println("w")
				flag = true
				break
			}
		}
		if !flag {
			fmt.Println("NA")
		}
	}
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

string s[3];
int main()
{
    while(cin >> s[0])
    {
        if(s[0] == "0" ) break;
         cin >> s[1] >> s[2];
         bool b = false, w = false;
         REP(3)
         {
             if(s[i][0] == 'b' && s[i][1] == 'b' && s[i][2] == 'b') b = true; 
             if(s[i][0] == 'w' && s[i][1] == 'w' && s[i][2] == 'w') w = true; 
             if(s[0][i] == 'b' && s[1][i] == 'b' && s[2][i] == 'b') b = true; 
             if(s[0][i] == 'w' && s[1][i] == 'w' && s[2][i] == 'w') w = true; 

         }
         if(s[0][0] == 'b' && s[1][1] == 'b' && s[2][2] == 'b' ) b = true;
         if(s[0][0] == 'w' && s[1][1] == 'w' && s[2][2] == 'w' ) w = true;
         if(s[0][2] == 'b' && s[1][1] == 'b' && s[2][0] == 'b' ) b = true;
         if(s[0][2] == 'w' && s[1][1] == 'w' && s[2][0] == 'w' ) w = true;

         if(w){ cout << "w" << endl; continue;}
         if(b){ cout << "b" << endl; continue;}
         cout << "NA" << endl; 
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    while(1){
        char ban[10][10] = {{0}};
        char field[10][10] = {{0}};
        cin >> field[0];
        if(field[0][0] == '0') break;
        cin >> field[1];
        cin >> field[2];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                ban[i+1][j+1] = field[i][j];
            }
        }
        for(int i = 1; i <= 3; i++){
            for(int j = 1; j <= 3; j++){
                if(i == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[l][j])cnt++;
                    }
                    if(cnt == 3){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
                if(j == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[i][l])cnt++;
                    }
                    if(cnt == 3){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
            }
        }
        if(ban[1][1] == ban[2][2] && ban[2][2] == ban[3][3]){
            printf("%c\n",ban[1][1]);
            goto end;
        }
        else if(ban[1][3] == ban[2][2] && ban[2][2] == ban[3][1]){
            printf("%c\n",ban[1][3]);
            goto end;
        }
        printf("NA\n");
        end:;
    }
	return 0;
}

C++: //AOJ 0183
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s[3];
	char w;
	while (1) {
		w = 'q';
		for (auto& i : s) {
			cin>>i;
			if(i == "0") return 0;
		}
		bool end = false;
		for (int i = 0; i < 3; i++) {
			char c = s[i][0];
			bool flag = true;
			for (int j = 0; j < 3; j++)
				if(s[i][j] != c) {flag = false;break;}
			if(flag && s[i][0] != '+') putchar(c),putchar('\n'),end = true;
		}
		if(end) goto fin;
		for (int i = 0; i < 3; i++) {
			char c = s[0][i];
			bool flag = true;
			for (int j = 0; j < 3; j++)
				if(s[j][i] != c) {flag = false;break;}
			if(flag && s[0][i] != '+') putchar(c),putchar('\n'),end = true;
		}
		if(end) goto fin;
		w = s[0][0];
		end = true;
		for (int i = 0; i < 3; i++)
			if(s[i][i] != w){end = false;break;}
		if(end && w != '+') {putchar(w);putchar('\n');goto fin;}
		w = s[0][2];
		end = true;
		for (int i = 0; i < 3; i++) {
			if(s[i][2-i] != w) {end = false;break;}
		}
		if(end && w != '+') putchar(w),putchar('\n');
fin:
		if(!end || w == '+') puts("NA");
	}
	return 0;
}

C++: //0066's copy
#include<iostream>
#include<string>
using namespace std;
int main(){
  string in;
  while(cin>>in,in[0]!='0'){
    for(int i=0;i<2;i++){
      string tmp;
      cin>>tmp;
      in+=tmp;
    }
    string han;
    //cout<<in[0]<<endl;
    if(
       (in[0]==in[1]&&in[1]==in[2])||
       (in[0]==in[4]&&in[4]==in[8])||
       (in[0]==in[3]&&in[3]==in[6])
       ){
      if(in[0]!='+')han=in[0];
    }
    else if((in[2]==in[4]&&in[4]==in[6])||(in[2]==in[5]&&in[5]==in[8]))
      {if(in[2]!='+')han=in[2];}
    else if(in[1]==in[4]&&in[4]==in[7]){if(in[1]!='+')han=in[1];}
    else if(in[3]==in[4]&&in[4]==in[5]){if(in[3]!='+')han=in[3];}
    else if(in[6]==in[7]&&in[7]==in[8]){if(in[6]!='+')han=in[6];}
    else han="NA";
    cout<<han<<endl;
  }

}

C++: #include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int l[][3]={{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
char c[9];

int main(){
	while(cin>>c[0]&&c[0]-'0'){
		rep(i,8)cin>>c[i+1];
		string ans="NA";
		rep(i,8)if(c[l[i][0]]!='+'&&c[l[i][0]]==c[l[i][1]]&&c[l[i][0]]==c[l[i][2]])ans=c[l[i][0]];
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
using namespace std;
char field[3][3];

void check() {
	for (int i = 0; i < 3; ++i) {
		if (field[i][0] != '+' && field[i][0] == field[i][1]) {
			if (field[i][1] == field[i][2]) {
				cout << field[i][2] << endl; return;
			}
		}
	}
	for (int i = 0; i < 3; ++i) {
		if (field[0][i] != '+' && field[0][i] == field[1][i]) {
			if (field[1][i] == field[2][i]) {
				cout << field[2][i] << endl; return;
			}
		}
	}

	if (field[0][0] != '+' && field[0][0] == field[1][1] && field[1][1] == field[2][2]) {
		cout << field[0][0] << endl;  return;
	}
	
	if (field[0][2] != '+' && field[0][2] == field[1][1] && field[1][1] == field[2][0]) {
		cout << field[0][2] << endl; return;
	}
	cout << "NA" << endl;
	return;
}

int main() {

	while (cin >> field[0][0], field[0][0]-'0') {
		cin >> field[0][1] >> field[0][2];

		for (int i = 1; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				cin >> field[i][j];
			}
		}
		check();
	}

	return 0;
}