ページ 11

2次元配列のラベリング C++

Posted: 2012年12月16日(日) 19:43
by momigear
マークされているものが上下左右(4値)でつながっているものを一つとしてカウントするプログラムを作りたいです。

□□■□■
□■■□□
□■□□■

この場合は3つです。
マークを判決した時に上下左右を判定するという流れだと思うんですがそれをうまく再起を利用してかけません。
shimaという関数のところを教えていただきたいです。

コード:


#include <iostream>
#include <string>
using namespace std;

const int size_x=5;
const int size_y=10;

void print_map(string [][size_x]);
void shima(string [][size_x],??);

int main()
{
  string map[size_y][size_x]={
    {"□","□","□","□","□","■","□","□","■","■"},
    {"□","□","□","□","□","□","■","□","■","■"},
    {"□","□","□","■","■","■","□","■","□","□"},
    {"□","□","■","■","□","■","□","□","□","□"},
    {"□","□","□","■","□","□","■","□","□","□"}};

  print_map(map);

  shima(map,??);


  return 0;
}


void print_map(string map[][size_x])
{
  for(int i=0;i<size_x;i++){
    for(int j=0;j<size_y;j++){
      cout << map[i][j];
    }
    cout << endl;
  }
}

void shima(string map[][size_y],??)
{
  //再帰による島のカウント

}


Re: 2次元配列のラベリング C++

Posted: 2012年12月16日(日) 23:57
by softya(ソフト屋)
前回のトピックが残っていますので新しい投稿はなさらないで下さい。
「2次元配列のラベリング(島化) • C言語交流フォーラム ~ mixC++ ~」
http://dixq.net/forum/viewtopic.php?f=3&t=12056

あと名前を変えることもフォーラムルールで禁止させて頂いています。
こちらは前のトピックがあるため不要ですので閉鎖させて頂きます。