I’d like to get the outer of a square array.
for example:the input is:
3
4 3 1
6 5 2
9 7 3
the output is
1 2 3
3 5 7
4 6 9
The original data was rotated 90 degrees to the right/clockwise.(the first number is n*n array). As my api is not the terminal or something, so I can only make the input a string split by “,”. However,when I was working on my code, even I wanted to test the outer I get from the input, the browser stopped me by showing error:
No action was found on the controller 'XXX' that matches the request.
I’m thinking there might be something wrong in my code causing that issue, can anyone help take a look?
[HttpGet]
[Route("api/sunflower/{string}")]
public string rotate(string input)
{
int[] inputArr = input.Split(',').Select(s => int.Parse(s)).ToArray();
string message = "";
// string newMessage = "";
string lastCol = "";
int squareNum = ((int)Math.Sqrt(inputArr.Length - 1));
// int rotate = (inputArr[0] + 2)%4;
for (int i = 0; i < squareNum; i++)
{
if (i == 0)
{
for (int j = 0; j < squareNum; j++)
{
message = message + inputArr[j + 1] + ",";
}
}
else if (i != squareNum - 1)
{
for (int j = 1; j <= (squareNum - 2); j++)
{
message = message + inputArr[squareNum * (j + 1) + 1] + ",";
lastCol = message + inputArr[j * squareNum + 1] + ",";
}
}
else
{
for (int j = 0; j < squareNum; j++)
{
message = message + inputArr[(squareNum - 1) * squareNum + j + 1];
}
}
for (int j = lastCol.Length - 1; j >= 0; j--)
{
message = message + lastCol[j];
}
}
return message;
}