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>
using namespace std;

char field[3][3];

char solve(){
	char tmp;
	bool flag;
	for(int i=0; i<3; i++){
		tmp = field[i][0];
		flag = true;
		for(int k=1; k<3; k++)
			if(field[i][k]!=tmp)
				flag = false;
		if(flag)
			return tmp;
	}
	for(int k=0; k<3; k++){
		tmp = field[0][k];
		flag = true;
		for(int i=1; i<3; i++)
			if(field[i][k]!=tmp)
				flag = false;
		if(flag)
			return tmp;
	}
	flag = true;
	tmp = field[0][0];
	for(int i=1,k=1; i<3&&k<3; i++,k++){
		if(field[i][k]!=tmp)
				flag = false;
	}
	if(flag)
		return tmp;
	flag = true;
	tmp = field[0][2];
	for(int i=1,k=1; i<3&&k>=0; i++,k--){
		if(field[i][k]!=tmp)
				flag = false;
	}
	if(flag)
		return tmp;
	return 'N';
}

int main(){
	while(true){
		for(int i=0; i<3; i++)
			for(int k=0; k<3; k++){
				cin >> field[i][k];
				if(field[0][0] == '0')
					return 0;
			}
		char ans = solve();
		if(ans == 'N')
			cout << "NA\n";
		else
			cout << ans << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  char in[3][4];
  while(cin>>in[0],in[0][0]!='0'){
    rep(i,2)cin>>in[i+1];
    bool h=false;
    rep(i,3){
      if(in[0][i]==in[1][i]&&in[1][i]==in[2][i]&&in[0][i]!='+'){cout<<in[0][i]<<endl;h=true;break;}
      else if(in[i][0]==in[i][1]&&in[i][1]==in[i][2]&&in[i][0]!='+'){cout<<in[i][0]<<endl;h=true;break}
    }
    if(!h){
      if(in[0][0]==in[1][1]&&in[1][1]==in[2][2]&&in[0][0]!='+')cout<<in[0][0]<<endl;
      else if(in[2][0]==in[1][1]&&in[1][1]==in[0][2]&&in[1][1]!='+')cout<<in[1][1]<<endl;
      else cout<<"NA"<<endl;
    }
  }


}

C++: #include<iostream>
main(){std::string s[3],A;for(int i,t;std::cin>>s[0]>>s[1]>>s[2],s[0]!="0";std::cout<<A<<"\n"){A="NA";for(i=3;i-->0;){t=s[i][0];if(t-43&&t==s[i][1]&t==s[i][2])A=t;t=s[0][i];if(t-43&&t==s[1][i]&t==s[2][i])A=t;}t=s[1][1];if(t-43&&t==s[0][0]&t==s[2][2]||t==s[0][2]&t==s[2][0])A=t;}}

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

int main(){
  char grid[3][3];
  while(cin >> grid[0][0]){
    if(grid[0][0] == '0')break;
    for(int i = 0 ; i < 3 ; i++ ){
      for(int j = 0 ; j < 3 ; j++ ){
	if(i == 0 && j == 0)continue;
	cin >> grid[j][i];
      }
    }
    char c[2] = {'b','w'},ans = 'S';
    for(int k = 0 ; k < 2 ; k++ ){

      for(int i = 0 ; i < 3 ; i++ ){
	if(grid[i][0] == c[k] &&
	   grid[i][1] == c[k] &&
	   grid[i][2] == c[k] )ans = c[k]; 

	if(grid[0][i] == c[k] &&
	   grid[1][i] == c[k] &&
	   grid[2][i] == c[k] )ans = c[k]; 
      }
      if(ans != 'S')break;
      if(grid[0][0] == c[k] && 
	 grid[1][1] == c[k] && 
	 grid[2][2] == c[k]  )ans = c[k];

      if(grid[0][2] == c[k] && 
	 grid[1][1] == c[k] && 
	 grid[2][0] == c[k]  )ans = c[k];
      if(ans != 'S')break;
    }
    if(ans == 'S')cout << "NA" << endl;
    else cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void)
{
  char table[3][3];

  while(1) {
    cin >> table[0];
    if(table[0][0] == '0') break;
    for(int i = 1 ; i < 3 ; i++) {
      cin >> table[i];
    }
    
    if(table[0][0] == 'b' && table[0][1] == 'b' && table[0][2] == 'b') cout << 'b' << endl;
    else if(table[1][0] == 'b' && table[1][1] == 'b' && table[1][2] == 'b') cout << 'b' << endl;
    else if(table[2][0] == 'b' && table[2][1] == 'b' && table[2][2] == 'b') cout << 'b' << endl;
    else if(table[0][0] == 'b' && table[1][1] == 'b' && table[2][2] == 'b') cout << 'b' << endl;
    else if(table[2][0] == 'b' && table[1][1] == 'b' && table[0][2] == 'b') cout << 'b' << endl;
    else if(table[0][0] == 'b' && table[1][0] == 'b' && table[2][0] == 'b') cout << 'b' << endl;
    else if(table[0][1] == 'b' && table[1][1] == 'b' && table[2][1] == 'b') cout << 'b' << endl;
    else if(table[0][2] == 'b' && table[1][2] == 'b' && table[2][2] == 'b') cout << 'b' << endl;

    else if(table[0][0] == 'w' && table[0][1] == 'w' && table[0][2] == 'w') cout << 'w' << endl;
    else if(table[1][0] == 'w' && table[1][1] == 'w' && table[1][2] == 'w') cout << 'w' << endl;
    else if(table[2][0] == 'w' && table[2][1] == 'w' && table[2][2] == 'w') cout << 'w' << endl;
    else if(table[0][0] == 'w' && table[1][1] == 'w' && table[2][2] == 'w') cout << 'w' << endl;
    else if(table[2][0] == 'w' && table[1][1] == 'w' && table[0][2] == 'w') cout << 'w' << endl;
    else if(table[0][0] == 'w' && table[1][0] == 'w' && table[2][0] == 'w') cout << 'w' << endl;
    else if(table[0][0] == 'w' && table[1][1] == 'w' && table[2][1] == 'w') cout << 'w' << endl;
    else if(table[0][2] == 'w' && table[1][2] == 'w' && table[2][2] == 'w') cout << 'w' << endl;

    else cout << "NA" << endl;
  } 
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
    char field[3][3];
    while(cin >> field[0], field[0][0] != '0'){
        bool isCorrect = true;
        for(int i=1; i < 3; i++){
            cin >> field[i];
        }

        for(int i=0; i < 3; i++){
            isCorrect = true;
            char stone = field[i][0];
            for(int j=1; j < 3; j++){
                if(stone != field[i][j]) isCorrect = false;
            }
            if(isCorrect){cout << stone << endl; break;}
        }

        for(int i=0; i < 3; i++){
            isCorrect = true;
            char stone = field[0][i];
            for(int j=1; j < 3; j++){
                if(stone != field[j][i]) isCorrect = false;
            }
            if(isCorrect){cout << stone << endl; break;}
        }

        if(isCorrect) continue;

        char stone = field[0][0];

        if(stone == field[1][1] && stone == field[2][2]){cout << stone << endl; continue;}

        stone = field[2][0];

        if(stone == field[1][1] && stone == field[0][2]){cout << stone << endl; continue;}

        cout << "NA" << endl;
    }
}