Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by dutt ( 14 years ago )
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
typedef unsigned int uint;

char newvalue(vector<string>& board, int x, int y) {
 int blacks = 0;
 if(board[x-1][y] == 'b')
  blacks++;
 if(board[x+1][y] == 'b')
  blacks++;
 if(board[x][y-1] == 'b')
  blacks++;
 if(board[x][y+1] == 'b')
  blacks++;
 if(board[x-1][y-1] == 'b')
  blacks++;
 if(board[x-1][y+1] == 'b')
  blacks++;
 if(board[x+1][y-1] == 'b')
  blacks++;
 if(board[x+1][y+1] == 'b')
  blacks++;
 if(blacks > 4)
  return 'b';
 else
  return 'w';
}
vector<string> fixboard(vector<string> board) {
 vector<string> newboard(board);
 for(uint x = 1; x < board.size()-1; ++x) { //columns
  for(uint y = 1; y < board.size()-1; ++y) { //rows
   newboard[x][y] = newvalue(board, x, y);
  }
 }
 return newboard;
}

int main(int argc, char** argv) {
 int testcases;
 cin >>testcases;
 int idx = 2;
 for(int a = 0; a < testcases; ++a) {
  int size;
  cin >>size;
  int iterations;
  cin >>iterations;
  cout <<"Board " <<a+1 <<endl;
  vector<string> board;
  for(int b = 0; b < size; ++b) {
   string line;
   cin >>line;
   board.push_back(line);
  }
  idx += size+1;
  board = fixboard(board);
  for(int b = 0; b < size; ++b)
   cout <<board[b] <<endl;
 }
}

 

Revise this Paste

Your Name: Code Language: