By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

Problem regarding a solution in uri online judge

P: 3
Hello, I am new at this forum and this is my first post. Today, I was solving problem no. 1827 in URI online judge.

Problem link

I wrote my code and tested it and it was giving correct answer and I am pretty sure that my logic is correct but in the online judge it is showing 90% wrong thus not accepted. I could not figure out the problem in my code. Please if anyone can take a look at my code.

My code link

Thanks to everyone.
Jun 16 '16 #1
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Please post your code. Virus concerns prevent me from following a link.
Jun 16 '16 #2

P: 3
Thanks for the assistance. The link that is given for my solution is from popular online code sharing site ideone.com (http://ideone.com/BJwzFY) which surely can never be a virus and I had to post the whole code to make everyone understand which could be bigger. So you could safely visit the link. Even then if you have the confusion, tell me. I will reply the code here. Thank you.
Jun 16 '16 #3

P: 3
Sorry for the inconvenience. I was out of my pc for a while so could not post the code. Here is my code:

Expand|Select|Wrap|Line Numbers
  1.     #include <stdio.h>
  2.  
  3.     int main()
  4.     {
  5.         int N, i, j, array[100][100]={{0}};
  6.  
  7.         while(scanf("%d", &N) != EOF){
  8.             for(i=0; i<N; i++){
  9.                 for(j=0; j<N; j++){
  10.                     if((i>=N/3 && i<(N-(N/3))) && (j>=N/3 && j<(N-(N/3)))){
  11.                         array[i][j] = 1;
  12.                     }
  13.                     else if(i==j){
  14.                         array[i][j] = 2;
  15.                     }
  16.                     else if(j == (N-i-1)){
  17.                         array[i][j] = 3;
  18.                     }
  19.                 }
  20.             }
  21.  
  22.             array[N/2][N/2] = 4;
  23.  
  24.             for(i=0; i<N; i++){
  25.                 for(j=0; j<N; j++){
  26.                     printf("%d", array[i][j]);
  27.                 }
  28.                 printf("\n");
  29.             }
  30.             printf("\n");
  31.         }
  32.  
  33.         return 0;
  34.     }
  35.  
  36.  
Jun 16 '16 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
From reading Problem 1827 you are to accept a number which is the size of a square matrix. In the URI example outout, they use 5. You should then allocate a 5x5 array. Snce this array is created at run time you use malloc() to allocate the memory.

Your solution doesn't do this. It creates a 100x100 array hard-coded.

My advice is to create a 5x5 array as shown in the Problem 1827 output example. Make your program produce the example output.

Post again after you have accomplished this.
Jun 16 '16 #5

Post your reply

Sign in to post your reply or Sign up for a free account.