Re: [algogeeks] test cases

2012-11-10 Thread rahul

On Oct 17, 2012 2:46 PM, w.s miller wentworth.miller6...@gmail.com
wrote:

 Hi,

 You are given N numbers. You have to perform two kinds of operations:
 U x y - x-th number becomes equal to y.
 Q x y - calculate the sum of distinct numbers from x-th to y-th. It means
 that the sum for the set {1, 2, 3, 2, 7} will be equal to 13 (1+2+3+7).
 Input

 The first line of input contains an integer N. 1=N=5
 The second line consists of N numbers.
 The third line consists of an integer Q. 1=Q=10
 The following Q lines will consist of queries of the form described in the
 task description.
 All numbers in input will fit in the signed 32-bit type.
 Output

 Output an answer for every query of the second type.
 Here is my code .But it is giving the wrong answer.Can anybody suggest me
 the test cases where it is giving Wrong Answer..

 #includestdio.h
 #includemath.h
 int main()
 {
 int list[5],i,n,j,sum,k,l;char c;long t;
 scanf(%d,n);
 for(i=0;in;i++)
 {
 scanf(%d,list[i]);
 }
 scanf(%ld,t);
 while(t)
 {
 sum=0;
 fflush(stdin);
 scanf(%c,c);
 scanf(%d%d,k,l);

 if(c=='Q'  (k=l))
 {
 for(i=k-1;il-1;i++)
 {
 for(j=i+1;jl;j++)
 {
if(list[i]==list[j])
   break;
else if((j==l-1) (list[i]!=list[j]))
{
   sum=sum+list[i];
}
 }
  }
  printf(%d\n,sum+list[l-1]);
  }
  if(c=='U')
  {
  list[k-1]=l;
  }
  t--;
 }
 return 0;
 }



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] test cases

2012-10-21 Thread Saurabh Kumar
Sorry, I couldn't find any test-case which could fail. I don't think there
is any logical error in that code. It works just fine.

You might be exceeding the time limit though.
Your approach is O(N^2) for N = 5 and 10 test-cases. it will be
nearly 10*5*5 calculations.

On 19 October 2012 15:33, w.s miller wentworth.miller6...@gmail.com wrote:

 @sourabh i applied the scenario as mentioned by u.but the problem is that
 it is still giving wrong answer for some test case.rest test cases are
 working fine.so can u help me out a bit here.


 On Thu, Oct 18, 2012 at 6:38 PM, Saurabh Kumar srbh.ku...@gmail.comwrote:

 Actually *fflush(stdin)* is the problem here, your reading of inputs is
 all messed up, at least on my machine( and probably on the machine you are
 submitting the code too).
 Maybe it's working fine on your particular environment but generally
 fflush() is only defined on output streams. (see this discussion -
 http://stackoverflow.com/questions/2979209/using-fflushstdin )

 I recommend putting one more scanf(%c, c).
 Your logic looks fine. For better runtime you might wanna use a
 data-structure though.

 On 18 October 2012 18:09, w.s miller wentworth.miller6...@gmail.comwrote:

 This code is failing only for a particular test case .can you plz
 suggest any such test case.


 On Thu, Oct 18, 2012 at 6:08 PM, w.s miller 
 wentworth.miller6...@gmail.com wrote:

 @Saurabh  kumar But i have used fflush(stdin),which flushes the
 standard input fille. So there is nothing in stdin when i go to read the
 character.so i dont think this is the problem.


 On Wed, Oct 17, 2012 at 5:36 PM, Saurabh Kumar srbh.ku...@gmail.comwrote:

 The problem is with:

 scanf(%c,c);
 scanf(%d%d,k,l);

 the first scanf goes on to read the '\n' character after you enter
 variable 't'.
 Try doing:
 scanf(%c,c); // Read the '\n' or SPACE character between
 't' and the next Q/U.
 scanf(%c,c); // Read the 'Q' or 'U'
 scanf(%d%d,k,l);

 On 17 October 2012 17:09, w.s miller 
 wentworth.miller6...@gmail.comwrote:

 Hi,

 You are given N numbers. You have to perform two kinds of operations:
 U x y - x-th number becomes equal to y.
 Q x y - calculate the sum of distinct numbers from x-th to y-th. It
 means that the sum for the set {1, 2, 3, 2, 7} will be equal to 13
 (1+2+3+7).
 Input

 The first line of input contains an integer N. 1=N=5
 The second line consists of N numbers.
 The third line consists of an integer Q. 1=Q=10
 The following Q lines will consist of queries of the form described
 in the task description.
 All numbers in input will fit in the signed 32-bit type.
 Output

 Output an answer for every query of the second type.
 Here is my code .But it is giving the wrong answer.Can anybody
 suggest me the test cases where it is giving Wrong Answer..

 #includestdio.h
 #includemath.h
 int main()
 {
 int list[5],i,n,j,sum,k,l;char c;long t;
 scanf(%d,n);
 for(i=0;in;i++)
 {
 scanf(%d,list[i]);
 }
 scanf(%ld,t);
 while(t)
 {
 sum=0;
 fflush(stdin);
 scanf(%c,c);
 scanf(%d%d,k,l);

 if(c=='Q'  (k=l))
 {
 for(i=k-1;il-1;i++)
 {
 for(j=i+1;jl;j++)
 {
if(list[i]==list[j])
   break;
else if((j==l-1) (list[i]!=list[j]))
{
   sum=sum+list[i];
}
 }
  }
  printf(%d\n,sum+list[l-1]);
  }
  if(c=='U')
  {
  list[k-1]=l;
  }
  t--;
 }
 return 0;
 }



  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 

Re: [algogeeks] test cases

2012-10-18 Thread Saurabh Kumar
Actually *fflush(stdin)* is the problem here, your reading of inputs is all
messed up, at least on my machine( and probably on the machine you are
submitting the code too).
Maybe it's working fine on your particular environment but generally
fflush() is only defined on output streams. (see this discussion -
http://stackoverflow.com/questions/2979209/using-fflushstdin )

I recommend putting one more scanf(%c, c).
Your logic looks fine. For better runtime you might wanna use a
data-structure though.

On 18 October 2012 18:09, w.s miller wentworth.miller6...@gmail.com wrote:

 This code is failing only for a particular test case .can you plz suggest
 any such test case.


 On Thu, Oct 18, 2012 at 6:08 PM, w.s miller 
 wentworth.miller6...@gmail.com wrote:

 @Saurabh  kumar But i have used fflush(stdin),which flushes the standard
 input fille. So there is nothing in stdin when i go to read the
 character.so i dont think this is the problem.


 On Wed, Oct 17, 2012 at 5:36 PM, Saurabh Kumar srbh.ku...@gmail.comwrote:

 The problem is with:

 scanf(%c,c);
 scanf(%d%d,k,l);

 the first scanf goes on to read the '\n' character after you enter
 variable 't'.
 Try doing:
 scanf(%c,c); // Read the '\n' or SPACE character between 't'
 and the next Q/U.
 scanf(%c,c); // Read the 'Q' or 'U'
 scanf(%d%d,k,l);

 On 17 October 2012 17:09, w.s miller wentworth.miller6...@gmail.comwrote:

 Hi,

 You are given N numbers. You have to perform two kinds of operations:
 U x y - x-th number becomes equal to y.
 Q x y - calculate the sum of distinct numbers from x-th to y-th. It
 means that the sum for the set {1, 2, 3, 2, 7} will be equal to 13
 (1+2+3+7).
 Input

 The first line of input contains an integer N. 1=N=5
 The second line consists of N numbers.
 The third line consists of an integer Q. 1=Q=10
 The following Q lines will consist of queries of the form described in
 the task description.
 All numbers in input will fit in the signed 32-bit type.
 Output

 Output an answer for every query of the second type.
 Here is my code .But it is giving the wrong answer.Can anybody suggest
 me the test cases where it is giving Wrong Answer..

 #includestdio.h
 #includemath.h
 int main()
 {
 int list[5],i,n,j,sum,k,l;char c;long t;
 scanf(%d,n);
 for(i=0;in;i++)
 {
 scanf(%d,list[i]);
 }
 scanf(%ld,t);
 while(t)
 {
 sum=0;
 fflush(stdin);
 scanf(%c,c);
 scanf(%d%d,k,l);

 if(c=='Q'  (k=l))
 {
 for(i=k-1;il-1;i++)
 {
 for(j=i+1;jl;j++)
 {
if(list[i]==list[j])
   break;
else if((j==l-1) (list[i]!=list[j]))
{
   sum=sum+list[i];
}
 }
  }
  printf(%d\n,sum+list[l-1]);
  }
  if(c=='U')
  {
  list[k-1]=l;
  }
  t--;
 }
 return 0;
 }



  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] test cases

2011-07-05 Thread segfault
Tell me how to write a test cases for given c program which are asked
in interview ?
Please give some examples.
Any website for it?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Test Cases

2011-07-01 Thread rShetty
#includestdio.h


int findMax(int *arr , int len)
{
 int i;
 int max = arr[0];
 for(i=0;ilen;i++)
 {
  if(arr[i]=max)
   max= arr[i];
  }
  printf(%d\n,max);
return max;
}


int findMin(int *arr ,int len)
{
 int min,i;
 for(i=0;ilen;i++)
 {
  min=arr[0];
  if(arr[i]arr[i+1])
   min= arr[i];
  }
  printf(%d\n,min);
return min;
}


int main()
{
 int arr[]={0,609,211,432,31,},len,p,m=0,n=0;
 len = sizeof(arr)/sizeof(arr[0]);
 n = findMax(arr,len);
 m = findMin(arr,len);
 p = n-m;
 printf(\n The Maximum Difference is\n);
 printf(%d\n,p);
 return 0;
}


This is the simple most inefficient code written for finding the
maximum difference .

I Need you to help me to come up better solutions to solve the problem
and the test cases on which it fails with alternate solutions .

Regards

Rajeev N B

I Blog @ www.opensourcemania.co.cc

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Test Cases

2011-05-10 Thread Akshata Sharma
write test cases for the division '/' operator..

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Test Cases

2011-05-10 Thread Carl Barton
Don't really get the question

On 10 May 2011 09:08, Akshata Sharma akshatasharm...@gmail.com wrote:

 write test cases for the division '/' operator..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Test Cases

2011-05-10 Thread Praveen Kumar
cases would be:
1. division by 0 raises an appropriate Exception
2. dividing 0 by any number should result in 0
3. dividing any number by 1 should give the same number
4. a = b*q + r i.e a/b should give q

On Tue, May 10, 2011 at 7:52 PM, Carl Barton odysseus.ulys...@gmail.comwrote:

 Don't really get the question


 On 10 May 2011 09:08, Akshata Sharma akshatasharm...@gmail.com wrote:

 write test cases for the division '/' operator..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.