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++: // #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}

// ------------------- include, typedef, define END. -------------------

string solve(vector<vector<char> > in){
	char mozi[3] = { 'b', 'w', '+' };
	string ret;
	FOR(i, 0, 3){
		FOR(j, 0, 3){
			bool flg = true;
			// 横に見る
			FOR(k, 0, 3){
				if (in[j][k] != mozi[i]){
					flg = false;
				}
			}
			if (flg)
				if (mozi[i] != '+')
					return ret=mozi[i];
			
			// 縦に見る
			flg = true;
			FOR(k, 0, 3){
				if (in[k][j] != mozi[i]){
					flg = false;
				}
			}
			if (flg)
				if (mozi[i] != '+')
					return ret = mozi[i];
		}
	}
	// 斜めに見る
	FOR(i, 0, 3){
		bool flg = true;
		for (int j = 0, k = 0; j < 3, k < 3; j++, k++){
			if (in[j][k] != mozi[i])
				flg = false;
		}
		if (flg)
			if (mozi[i] != '+')
				return ret = mozi[i];

		flg = false;
		for (int j = 2, k = 0; j >=0, k <3; j--, k++){
			if (in[j][k] != mozi[i])
				flg = false;
		}
		if (flg)
			if (mozi[i] != '+')
				return ret = mozi[i];
	}
	return "NA";
}

int main(){
	int n = 0;
	string firstLine;

	while (getline(cin, firstLine), firstLine != "0"){
		vector<vector<char> > in(3,vector<char>(3));
		// 最初の行
		istringstream stream(firstLine);
		char temp;
		int count = 0;
		while (stream >> temp,!stream.eof()){
			in[0][count] = temp;
			count++;
		}
		// 2行目・3行目
		FOR(i, 1, 3){
			FOR(j, 0, 3){
				cin >> temp;
				in[i][j] = temp;
			}
		}
		cout << solve(in) << endl;
		//cin >> temp; 
		cin.ignore();
	}

	return 0;
}

C++: #include<iostream>
#include<utility>
#include<queue>
#include<functional>
#include<algorithm>
#include<cstring>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define INF (2<<25)
typedef pair<int,int> pii;
typedef vector<int> vi;

int main()
{
	while(true)
	{
		string a[3];
		cin>>a[0]>>a[1]>>a[2];
		if(a[0]=="0")break;
		
		bool isdraw=true;
		
		FOR(i,3)
		{
			bool equal[2]={1,1};
			FOR(j,3)
			{
				if(a[i][j]!=a[i][0])equal[0]=false;
				if(a[j][i]!=a[0][i])equal[1]=false;
			}
			FOR(j,2)
			{
				if(equal[j]&&a[(j?0:i)][j?i:0]!='+')
				{
					isdraw=false;
					cout<<a[(j?0:i)][j?i:0]<<endl;
				}
			}
		}
		bool equal[2]={1,1};
		FOR(i,3)
		{
			if(a[i][i]!=a[0][0])equal[0]=false;
			if(a[i][2-i]!=a[0][2])equal[1]=false;
		}
		FOR(j,2)
			{
				if(equal[j]&&a[(j?0:0)][j?0:2]!='+')
				{
					isdraw=false;
					cout<<a[(j?0:0)][j?0:2]<<endl;
				}
			}
		if(isdraw)cout<<"NA"<<endl;
		
	}
}

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

char field[3][4];

char solve(){
	for(int i=0; i<3; i++){
		if(field[i][0] == field[i][1] && field[i][1] == field[i][2])
			return field[i][0];
	}
	for(int k=0; k<3; k++){
		if(field[0][k] == field[1][k] && field[1][k] == field[2][k])
			return field[0][k];
	}
	if(field[0][0] == field[1][1] && field[1][1] == field[2][2])
		return field[0][0];
	if(field[0][2] == field[1][1] && field[1][1] == field[2][0])
		return field[0][2];
	return 'N';
}

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

C++: #include <stdio.h>

int main(void)
{
	int n, m;
	int in[1000][100];
	int countF[100], countS[100];
	int ans[100];
	int i, j;
	
	while (1){
		scanf("%d %d", &n, &m);
		
		if (n == 0 && m == 0)break;
		
		for (i = 0; i < 100; i++){
				for (j = 0; j < 1000; j++){
				in[i][j] = 0;
			}
			
			countF[i] = 0;
			countS[i] = 0;
			ans[i] = 0;
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < m; j++){
				scanf("%d", &in[i][j]);
				
				if (in[i][j] == 1){
					countF[j]++;
					countS[j]++;
				}
			}
		}
		
		for (i = 0; i < m - 1; i++){
			for (j = 0; j < m - i - 1; j++){
				if (countS[j] < countS[j + 1]){
					countS[j] += countS[j + 1];
					countS[j + 1] = countS[j] - countS[j + 1];
					countS[j] -= countS[j + 1];
				}
			}
		}
		
		for (i = 0; i < m; i++){
			for (j = 0; j < m; j++){
				if (countS[i] == countF[j]){
					ans[j] = i + 1;
					countF[j] = -1;
						break;
				}
			}
		}
		
		for (i = 0; i < m; i++){
			printf("%d", ans[i]);
			if (i < m - 1){
				printf("\n");
			}
		}
		printf("\n");
	}
	
	return (0);
}