当前位置: 首页>>代码示例>>C++>>正文


C++ Coordinate::advance方法代码示例

本文整理汇总了C++中Coordinate::advance方法的典型用法代码示例。如果您正苦于以下问题:C++ Coordinate::advance方法的具体用法?C++ Coordinate::advance怎么用?C++ Coordinate::advance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Coordinate的用法示例。


在下文中一共展示了Coordinate::advance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........

        // Masukkan tiap karakter ke map
        for (unsigned int i = 0; i < crosswordWord->word.length(); ++i) {
            char ch = crosswordWord->word[i];
            if (EXIST(position, crosswordGrid)) {
                if (crosswordGrid[position] != ch) {
                    crosswordGrid[position] = '?';
                    contradictions.push_back(position);
                }
            } else {
                crosswordGrid[position] = ch;
            }

            // Memperbarui batas crossword: topLeft dan bottomRight
            if (firstCharacter) {
                firstCharacter = false;
                topLeft = bottomRight = position;
            } else {
                if (position.row < topLeft.row) {
                    topLeft.row = position.row;
                }
                if (position.col < topLeft.col) {
                    topLeft.col = position.col;
                }
                if (position.row > bottomRight.row) {
                    bottomRight.row = position.row;
                }
                if (position.col > bottomRight.col) {
                    bottomRight.col = position.col;
                }
            }

            // Memajukan koordinat position sesuai dengan arah kata
            position.advance(crosswordWord->direction);
        }
    }

    // Cetak grid sebelum diisi
    printf("Teka-teki silang yang pada masukan:\n\n");
    printCrossword(crosswordGrid);

    // Jika ada kontradiksi, keluarkan daftarnya
    if (!contradictions.empty()) {
        string message = "Terdapat kontradiksi pada koordinat";
        for (int i = 0; i < contradictions.size(); ++i) {
            if (i == 0) {
                sprintf(buffer, " (%d, %d)", contradictions[i].row, contradictions[i].col);
            } else if (i + 1 < contradictions.size()) {
                sprintf(buffer, ", (%d, %d)", contradictions[i].row, contradictions[i].col);
            } else if (contradictions.size() == 2) {
                sprintf(buffer, " dan (%d, %d)", contradictions[i].row, contradictions[i].col);
            } else {
                sprintf(buffer, ", dan (%d, %d)", contradictions[i].row, contradictions[i].col);
            }
            message += buffer;
        }
        TERMINATE("%s\n", message.c_str());
    }

    // Final check: cari kata baru yang terbentuk, atau cari kata yang tidak valid
    for (map<Coordinate, char>::iterator startIterator = crosswordGrid.begin();
            startIterator != crosswordGrid.end(); ++startIterator) {
        Coordinate start = startIterator->first;
        for (int direction = 0; direction < 2; ++direction) {
            Coordinate position = start;
            string word;
开发者ID:azaky,项目名称:tugas3-ca-irk,代码行数:67,代码来源:solver_checker.cpp

示例2: main


//.........这里部分代码省略.........

    // Langsung berhenti saat keluaran kosong
    ASSERT(!outputWords.empty(), "Tidak ada kata pada keluaran!\n");

    // Memasukkan seluruh kata ke dalam grid yang direpresentasikan oleh map sambil mendaftar
    // semua kontradiksi yang ada pada grid
    map<Coordinate, char> crosswordGrid;
    map<Coordinate, CrosswordWord> directionMapping[2];
    vector<Coordinate> contradictions;

    for (vector<CrosswordWord>::iterator crosswordWord = outputWords.begin();
            crosswordWord != outputWords.end(); ++crosswordWord) {
        Coordinate position = crosswordWord->start;

        // Periksa apakah sudah ada kata pada koordinat dan arah yang sama
        ASSERT(!EXIST(position, directionMapping[crosswordWord->direction]),
                "Ada dua kata pada koordinat (%d, %d) %s\n", position.row, position.col,
                crosswordWord->direction == ACCROSS ? "mendatar" : "menurun");
        directionMapping[crosswordWord->direction][position] = *crosswordWord;

        // Masukkan tiap karakter ke map
        for (unsigned int i = 0; i < crosswordWord->word.length(); ++i) {
            char ch = crosswordWord->word[i];
            if (EXIST(position, crosswordGrid)) {
                if (crosswordGrid[position] != ch) {
                    crosswordGrid[position] = '?';
                    contradictions.push_back(position);
                }
            } else {
                crosswordGrid[position] = ch;
            }

            // Memajukan koordinat position sesuai dengan arah kata
            position.advance(crosswordWord->direction);
        }
    }

    // Cetak grid
    printf("Teka-teki silang yang terbentuk:\n\n");
    printCrossword(crosswordGrid);

    // Jika ada kontradiksi, keluarkan daftarnya
    if (!contradictions.empty()) {
        string message = "Terdapat kontradiksi pada koordinat";
        for (int i = 0; i < contradictions.size(); ++i) {
            if (i == 0) {
                sprintf(buffer, " (%d, %d)", contradictions[i].row, contradictions[i].col);
            } else if (i + 1 < contradictions.size()) {
                sprintf(buffer, ", (%d, %d)", contradictions[i].row, contradictions[i].col);
            } else if (contradictions.size() == 2) {
                sprintf(buffer, " dan (%d, %d)", contradictions[i].row, contradictions[i].col);
            } else {
                sprintf(buffer, ", dan (%d, %d)", contradictions[i].row, contradictions[i].col);
            }
            message += buffer;
        }
        TERMINATE("%s\n", message.c_str());
    }

    // Final check: cari kata baru yang terbentuk, atau cari kata yang tidak valid
    for (map<Coordinate, char>::iterator startIterator = crosswordGrid.begin();
            startIterator != crosswordGrid.end(); ++startIterator) {
        Coordinate start = startIterator->first;
        for (int direction = 0; direction < 2; ++direction) {
            Coordinate position = start;
            string word;
开发者ID:azaky,项目名称:tugas3-ca-irk,代码行数:67,代码来源:generator_checker.cpp


注:本文中的Coordinate::advance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。