this is the code:
#include <iostream>
#include <queue>
#include <unordered_set>
using namespace std;
string swap(string s, int i, int j) {
char temp = s[i];
s[i] = s[j];
s[j] = temp;
return s;
}
int slidingPuzzle(vector<vector<int>>& board) {
int rows = 2;
int cols = 3;
string target = "1234560";
string start = "";
for (int i = 0; i < rows; i++) {
for (int j = 0; i < cols; j++) {
start = start + to_string(board[i][j]);
}
}
vector<vector<int>> neighbour = {
{1, 3}, {0, 4, 2}, {1, 5}, {0, 4}, {3, 1, 5}, {4, 2},
};
queue<string> q;
unordered_set<string> visited;
q.push(start);
visited.insert(start);
int step = 0;
while (!q.empty()) {
int sz = q.size();
for (int i = 0; i < sz; i++) {
string cur = q.front();
if (target == cur) {
return step;
}
int idx = 0;
for (; cur[idx] != '0'; idx++)
;
for (int adj : neighbour[idx]) {
string new_board = swap(cur, adj, idx);
if (!visited.count(new_board)) {
q.push(new_board);
visited.insert(new_board);
}
}
}
step++;
}
return -1;
}
int main() {
vector<vector<int>> board = {
{1, 2, 3},
{4, 0, 5},
};
int a = slidingPuzzle(board);
cout << a << endl;
}
When I start compiling this code I get the following problem:
main.cpp:11:36: error: a space is required between consecutive right angle brackets (use '> >')
int slidingPuzzle(vector<vector<int>>& board) {
^~
> >
...
I checked the relevant information and found out that it is because In C++03 and its previous versions, consecutive closing angle brackets (>>) are not supported.
When I check the default c++ version compiled by clang++ program
clang++ -E -x c++ - -dM < /dev/null | grep __cplusplus
with output:
#define __cplusplus 199711L
My question is: How to modify the default c++ version when clang++ compiles?