+ 2
How to pass a 2 D array of unknown n elements into the a function in C.
I want to pass a 2D array of integers with unknown n that I'll input from the user at the run time. I am getting strange errors when attempting to pass the array to the function. Can someone explain with the help of a small code example?
18 Answers
+ 1
Here is the question:
In order to impress Chefina, Chef is trying to improve his chess calculation skills.
Today, Chef took a big chessboard with N rows (numbered 1 through N) and N columns (numbered 1 through N). Let's denote the square in row r and column c of the chessboard by (r,c). Chef wants to place some queens on this chessboard in such a way that the following conditions are satisfied:
Each square of the board contains at most one queen.
There are exactly Nâ2 queens on the board.
All squares are reachable by at least one queen.
A queen can reach all cells along the row, column, and diagonals it is placed at.
Formally, a queen placed at square (r,c) can reach square (x,y) if at least one of the following conditions holds:
x=r
y=c
r+c=x+y
râc=xây
Help Chef find a possible distribution of queens. If there are multiple solutions, you may find any one. It is guaranteed that under the given constraints, a solution always exists.
Input Format
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first and only line of each test case contains a single integer N.
Output Format
For each test case, print N lines. For each valid i, the i-th of these lines should contain a single string with length N describing row i of the chessboard; for each valid j, the j-th character of this string should be 'Q' if there is a queen in the square (i,j) or '.' if this square is empty. Please note you have to place exactly Nâ2 queens.
Constraints
1â€Tâ€100
3â€Nâ€100
The sum of N2 over all test cases does not exceed 105
Sample Input 1
2
3
4
Sample Output 1
...
.Q.
...
...Q
....
.Q..
....
Explanation
Test Case 1: The Queen in the middle covers all squares on the board.
Test Case 2: The Queen at square (1,4) covers all squares in the first row and the last column, while the other Queen covers all the other squares.
+ 2
Ruchika Sehgal can u tell what u expecting as i tried with inputs your code working fine their is not synthetic errors learn about STL you can reduce many lines
+ 2
This problem will not visible to other becz you have participated in challenges i guess others cannot see your question without registration
+ 2
Ruchika Sehgal I changed something in your code based on the problem statement like taking number of test cases and removed some unwanted codes. I'm not sure it would work properly for big inputs, just check it out.
https://code.sololearn.com/cCxIe0zA342F/?ref=app
+ 1
Can you post the code you got?
+ 1
The error?
+ 1
the error, the code, everything!
Ruchika Sehgal what does code chef have to do with anything? Please post the code
+ 1
'n' undeclared here (not in a function)
+ 1
Nah, post it in the playground, save it, and share it please. Plus its cut off
+ 1
put it in the playground and share it bud
+ 1
Okays
+ 1
www.codechef.com/SNCK1B21/problems/QPLACE
+ 1
Am trying to solve this question
+ 1
Oh
+ 1
Martin Taylor Thanks for the suggestion.
0
I am actually attempting a Codechef problem