Re: [algogeeks] Please explain

2012-06-14 Thread Lomash Goyal
void pushreverse(int data)
{
int temp;
if(top==0)
{
push(data);
return;
}
else
temp=pop();
pushreverse(data);
push(temp);

}
int reversestack()
{
//static int arr[50];
 int top2=0;
int i;
if(top==0)
{ return top2;
}
 top2=pop();
reversestack();
pushreverse(top2);
 }


On Thu, Jun 14, 2012 at 2:16 PM, sengar.mahi  wrote:

> sry i got confused its 3 then 2 then 1. i thought its 321
>
>
> On Thu, Jun 14, 2012 at 2:13 PM, Mahendra Sengar wrote:
>
>> main()
>>
>> {
>>
>> static i=3;
>>
>> printf("%d",i--);
>>
>> return i>0 ? main():0;
>>
>> }
>>
>>
>> the above code gives output 321
>> Please Explain how?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/algogeeks/-/G-wUarnLpbEJ.
>> 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.
>



-- 
Regards

Lomash Goyal
*
*

-- 
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] Please explain

2012-06-14 Thread sengar.mahi
sry i got confused its 3 then 2 then 1. i thought its 321

On Thu, Jun 14, 2012 at 2:13 PM, Mahendra Sengar wrote:

> main()
>
> {
>
> static i=3;
>
> printf("%d",i--);
>
> return i>0 ? main():0;
>
> }
>
>
> the above code gives output 321
> Please Explain how?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/G-wUarnLpbEJ.
> 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] Please explain

2012-06-14 Thread Mahendra Sengar


main()

{

static i=3;

printf("%d",i--);

return i>0 ? main():0;

}


the above code gives output 321
Please Explain how?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/G-wUarnLpbEJ.
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] Please explain its working..

2011-09-03 Thread annarao kataru
@sanjay  then why to put  str  in printf statement  .  is there no effect of
placing str in printf stat  . plz clarify??

-- 
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] Please explain its working..

2011-08-21 Thread Sanjay Rajpal
In the prototype of printf, first argument is a format string, which here is
str.

However generally we see a const string there which is stored in data area.

Rest of things are simple.

Hope u got it :)
Sanju
:)



On Sun, Aug 21, 2011 at 1:15 PM, Amol Sharma  wrote:

> study about the argument of printf.it will be clear thenactually
> str is acting as a format string in your code
> --
>
>
> Amol Sharma
> Third Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>    
> 
>
>
>
>
>
> On Mon, Aug 22, 2011 at 1:34 AM, JAIDEV YADAV  wrote:
>
>> i think it is simple as it seems ...
>>
>>
>> On Mon, Aug 22, 2011 at 1:26 AM, Romil ... wrote:
>>
>>> #include
>>> int main()
>>> {
>>> char *str;
>>> str = "%s";
>>> printf(str, "K\n");
>>> return 0;
>>> }
>>>
>>>
>>>
>>> --
>>> Romil
>>>
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> JaiDev Yadav
>> (National Yoga Champion)
>> Computer Engg. Dept.
>> National Institute of Technology
>> Kurukshetra,Haryana
>>
>> --
>> 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.



Re: [algogeeks] Please explain its working..

2011-08-21 Thread Amol Sharma
study about the argument of printf.it will be clear thenactually str
is acting as a format string in your code
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
 






On Mon, Aug 22, 2011 at 1:34 AM, JAIDEV YADAV  wrote:

> i think it is simple as it seems ...
>
>
> On Mon, Aug 22, 2011 at 1:26 AM, Romil ... wrote:
>
>> #include
>> int main()
>> {
>> char *str;
>> str = "%s";
>> printf(str, "K\n");
>> return 0;
>> }
>>
>>
>>
>> --
>> Romil
>>
>>
>>  --
>> 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.
>>
>
>
>
> --
> JaiDev Yadav
> (National Yoga Champion)
> Computer Engg. Dept.
> National Institute of Technology
> Kurukshetra,Haryana
>
>  --
> 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] Please explain its working..

2011-08-21 Thread JAIDEV YADAV
i think it is simple as it seems ...

On Mon, Aug 22, 2011 at 1:26 AM, Romil ...  wrote:

> #include
> int main()
> {
> char *str;
> str = "%s";
> printf(str, "K\n");
> return 0;
> }
>
>
>
> --
> Romil
>
>
>  --
> 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.
>



-- 
JaiDev Yadav
(National Yoga Champion)
Computer Engg. Dept.
National Institute of Technology
Kurukshetra,Haryana

-- 
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] Please explain its working..

2011-08-21 Thread Romil .......
#include
int main()
{
char *str;
str = "%s";
printf(str, "K\n");
return 0;
}



-- 
Romil

-- 
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] please explain

2011-06-30 Thread Arpit Sood
he was pointing to the abnormality in behaviour and not actual algorithm :D

On Fri, Jul 1, 2011 at 11:50 AM, surender sanke  wrote:

> why two loops, find max and min and returns its difference
>
> surender
>
> On Fri, Jul 1, 2011 at 11:32 AM, sunny agrawal wrote:
>
>> in function it is pointer pointing to an array of 6 elements , pointer
>> have size equal to word size in the system which is 4bytes for 32 bit
>> operating system
>>
>> in main it is array of 6 integers so 24 bytes
>>
>> Don't get confused with same names, see the scope and type of arr in both
>>
>>
>> On Fri, Jul 1, 2011 at 11:28 AM, shady  wrote:
>>
>>> why is the value of sizeof(arr) in maxdiff function = 4 ?
>>> where as in main function it is 24
>>>
>>>
>>> On Fri, Jul 1, 2011 at 11:05 AM, Vishal Thanki 
>>> wrote:
>>>
 Rujin is right, here is the code which compiles..

 vishal@ubuntu:~/progs/c\ 11:04:37 AM >$ cat alg.c
 #include
 int maxdiff(int arr[]);
 int main()
 {
int p,arr[]={2,4,1,6,23,4};
p=maxdiff(arr);
printf("\n MAX Diff is \t %d",p);
 return 0;
 }
 int maxdiff(int arr[])
 {
int diff=0,len,i,j;
unsigned p;
len=sizeof(arr)/sizeof(arr[0]);
for(i=0;i>>>{
for(j=i;j>>>{
p=arr[j]-arr[i];
if((p-diff)>0)
diff=p;
}
}
return diff;
 }
 vishal@ubuntu:~/progs/c\ 11:04:40 AM >$ gcc alg.c -Wall


 On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa 
 wrote:
 > actually u r passing arr,and receiving arr[] which actually receives
 the
 > first element address. So arr will be a reference to first address. so
 its
 > size will be 4  bytes and arr size will also be 4 bytes. so ur len
 contains
 > only 1. so ur loop runs only once.i hope it clears.
 >
 > On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh 
 wrote:
 >>
 >> still it's not working
 >>
 >> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao 
 wrote:
 >>>
 >>> int maxdiff(int );
 >>> int maxdiff(int arr[]);
 >>> The signatures of  maxdiff function are  not the same.
 >>>
 >>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh 
 >>> wrote:
 
  this code gives an error ([Warning] passing arg 1 of `maxdiff'
 makes
  integer from pointer without a cast) . Please explain the reasons.
 
 
  #include
  #include
  int maxdiff(int );
  main()
  {
    int p,arr[]={2,4,1,6,23,4};
    p=maxdiff(arr);
    printf("\n MAX Diff is \t %d",p);
    getch();
    }
  int maxdiff(int arr[])
  {
  int diff=0,len,i,j;
  unsigned p;
  len=sizeof(arr)/sizeof(arr[0]);
  for(i=0;i>>>  {
    for(j=i;j>>>    {
   p=arr[j]-arr[i];
   if((p-diff)>0)
   diff=p;
    }
  }
  return diff;
  }
 
  --
  with regards,
  Ashwini kumar singh
  ECE Final yr.
  NIT Allahabad
 
 
  --
  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.
 >>
 >>
 >>
 >> --
 >> with regards,
 >> Ashwini kumar singh
 >> ECE Final yr.
 >> MNNIT Allahabad
 >> Mobile: 7505519402
 >>
 >> --
 >> 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.
 >
 >
 >
 > --
 > Varun Pahwa
 > B.Tech (IT)
 > 7th Sem.
 > Indian Institute of Information Technology Allahabad.
 > Ph : 09793899112 ,080118

Re: [algogeeks] please explain

2011-06-30 Thread surender sanke
why two loops, find max and min and returns its difference

surender

On Fri, Jul 1, 2011 at 11:32 AM, sunny agrawal wrote:

> in function it is pointer pointing to an array of 6 elements , pointer have
> size equal to word size in the system which is 4bytes for 32 bit operating
> system
>
> in main it is array of 6 integers so 24 bytes
>
> Don't get confused with same names, see the scope and type of arr in both
>
>
> On Fri, Jul 1, 2011 at 11:28 AM, shady  wrote:
>
>> why is the value of sizeof(arr) in maxdiff function = 4 ?
>> where as in main function it is 24
>>
>>
>> On Fri, Jul 1, 2011 at 11:05 AM, Vishal Thanki wrote:
>>
>>> Rujin is right, here is the code which compiles..
>>>
>>> vishal@ubuntu:~/progs/c\ 11:04:37 AM >$ cat alg.c
>>> #include
>>> int maxdiff(int arr[]);
>>> int main()
>>> {
>>>int p,arr[]={2,4,1,6,23,4};
>>>p=maxdiff(arr);
>>>printf("\n MAX Diff is \t %d",p);
>>> return 0;
>>> }
>>> int maxdiff(int arr[])
>>> {
>>>int diff=0,len,i,j;
>>>unsigned p;
>>>len=sizeof(arr)/sizeof(arr[0]);
>>>for(i=0;i>>{
>>>for(j=i;j>>{
>>>p=arr[j]-arr[i];
>>>if((p-diff)>0)
>>>diff=p;
>>>}
>>>}
>>>return diff;
>>> }
>>> vishal@ubuntu:~/progs/c\ 11:04:40 AM >$ gcc alg.c -Wall
>>>
>>>
>>> On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa 
>>> wrote:
>>> > actually u r passing arr,and receiving arr[] which actually receives
>>> the
>>> > first element address. So arr will be a reference to first address. so
>>> its
>>> > size will be 4  bytes and arr size will also be 4 bytes. so ur len
>>> contains
>>> > only 1. so ur loop runs only once.i hope it clears.
>>> >
>>> > On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh 
>>> wrote:
>>> >>
>>> >> still it's not working
>>> >>
>>> >> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao 
>>> wrote:
>>> >>>
>>> >>> int maxdiff(int );
>>> >>> int maxdiff(int arr[]);
>>> >>> The signatures of  maxdiff function are  not the same.
>>> >>>
>>> >>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh 
>>> >>> wrote:
>>> 
>>>  this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
>>>  integer from pointer without a cast) . Please explain the reasons.
>>> 
>>> 
>>>  #include
>>>  #include
>>>  int maxdiff(int );
>>>  main()
>>>  {
>>>    int p,arr[]={2,4,1,6,23,4};
>>>    p=maxdiff(arr);
>>>    printf("\n MAX Diff is \t %d",p);
>>>    getch();
>>>    }
>>>  int maxdiff(int arr[])
>>>  {
>>>  int diff=0,len,i,j;
>>>  unsigned p;
>>>  len=sizeof(arr)/sizeof(arr[0]);
>>>  for(i=0;i>>  {
>>>    for(j=i;j>>    {
>>>   p=arr[j]-arr[i];
>>>   if((p-diff)>0)
>>>   diff=p;
>>>    }
>>>  }
>>>  return diff;
>>>  }
>>> 
>>>  --
>>>  with regards,
>>>  Ashwini kumar singh
>>>  ECE Final yr.
>>>  NIT Allahabad
>>> 
>>> 
>>>  --
>>>  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.
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> with regards,
>>> >> Ashwini kumar singh
>>> >> ECE Final yr.
>>> >> MNNIT Allahabad
>>> >> Mobile: 7505519402
>>> >>
>>> >> --
>>> >> 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.
>>> >
>>> >
>>> >
>>> > --
>>> > Varun Pahwa
>>> > B.Tech (IT)
>>> > 7th Sem.
>>> > Indian Institute of Information Technology Allahabad.
>>> > Ph : 09793899112 ,08011820777
>>> > Official Email :: rit2008...@iiita.ac.in
>>> > Another Email :: varunpahwa.ii...@gmail.com
>>> >
>>> > People who fail to plan are those who plan to fail.
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Algorithm Geeks" group.
>>> > To post

Re: [algogeeks] please explain

2011-06-30 Thread sunny agrawal
in function it is pointer pointing to an array of 6 elements , pointer have
size equal to word size in the system which is 4bytes for 32 bit operating
system

in main it is array of 6 integers so 24 bytes

Don't get confused with same names, see the scope and type of arr in both

On Fri, Jul 1, 2011 at 11:28 AM, shady  wrote:

> why is the value of sizeof(arr) in maxdiff function = 4 ?
> where as in main function it is 24
>
>
> On Fri, Jul 1, 2011 at 11:05 AM, Vishal Thanki wrote:
>
>> Rujin is right, here is the code which compiles..
>>
>> vishal@ubuntu:~/progs/c\ 11:04:37 AM >$ cat alg.c
>> #include
>> int maxdiff(int arr[]);
>> int main()
>> {
>>int p,arr[]={2,4,1,6,23,4};
>>p=maxdiff(arr);
>>printf("\n MAX Diff is \t %d",p);
>> return 0;
>> }
>> int maxdiff(int arr[])
>> {
>>int diff=0,len,i,j;
>>unsigned p;
>>len=sizeof(arr)/sizeof(arr[0]);
>>for(i=0;i>{
>>for(j=i;j>{
>>p=arr[j]-arr[i];
>>if((p-diff)>0)
>>diff=p;
>>}
>>}
>>return diff;
>> }
>> vishal@ubuntu:~/progs/c\ 11:04:40 AM >$ gcc alg.c -Wall
>>
>>
>> On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa 
>> wrote:
>> > actually u r passing arr,and receiving arr[] which actually receives the
>> > first element address. So arr will be a reference to first address. so
>> its
>> > size will be 4  bytes and arr size will also be 4 bytes. so ur len
>> contains
>> > only 1. so ur loop runs only once.i hope it clears.
>> >
>> > On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh 
>> wrote:
>> >>
>> >> still it's not working
>> >>
>> >> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao 
>> wrote:
>> >>>
>> >>> int maxdiff(int );
>> >>> int maxdiff(int arr[]);
>> >>> The signatures of  maxdiff function are  not the same.
>> >>>
>> >>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh 
>> >>> wrote:
>> 
>>  this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
>>  integer from pointer without a cast) . Please explain the reasons.
>> 
>> 
>>  #include
>>  #include
>>  int maxdiff(int );
>>  main()
>>  {
>>    int p,arr[]={2,4,1,6,23,4};
>>    p=maxdiff(arr);
>>    printf("\n MAX Diff is \t %d",p);
>>    getch();
>>    }
>>  int maxdiff(int arr[])
>>  {
>>  int diff=0,len,i,j;
>>  unsigned p;
>>  len=sizeof(arr)/sizeof(arr[0]);
>>  for(i=0;i>  {
>>    for(j=i;j>    {
>>   p=arr[j]-arr[i];
>>   if((p-diff)>0)
>>   diff=p;
>>    }
>>  }
>>  return diff;
>>  }
>> 
>>  --
>>  with regards,
>>  Ashwini kumar singh
>>  ECE Final yr.
>>  NIT Allahabad
>> 
>> 
>>  --
>>  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.
>> >>
>> >>
>> >>
>> >> --
>> >> with regards,
>> >> Ashwini kumar singh
>> >> ECE Final yr.
>> >> MNNIT Allahabad
>> >> Mobile: 7505519402
>> >>
>> >> --
>> >> 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.
>> >
>> >
>> >
>> > --
>> > Varun Pahwa
>> > B.Tech (IT)
>> > 7th Sem.
>> > Indian Institute of Information Technology Allahabad.
>> > Ph : 09793899112 ,08011820777
>> > Official Email :: rit2008...@iiita.ac.in
>> > Another Email :: varunpahwa.ii...@gmail.com
>> >
>> > People who fail to plan are those who plan to fail.
>> >
>> > --
>> > 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 y

Re: [algogeeks] please explain

2011-06-30 Thread shady
why is the value of sizeof(arr) in maxdiff function = 4 ?
where as in main function it is 24

On Fri, Jul 1, 2011 at 11:05 AM, Vishal Thanki wrote:

> Rujin is right, here is the code which compiles..
>
> vishal@ubuntu:~/progs/c\ 11:04:37 AM >$ cat alg.c
> #include
> int maxdiff(int arr[]);
> int main()
> {
>int p,arr[]={2,4,1,6,23,4};
>p=maxdiff(arr);
>printf("\n MAX Diff is \t %d",p);
> return 0;
> }
> int maxdiff(int arr[])
> {
>int diff=0,len,i,j;
>unsigned p;
>len=sizeof(arr)/sizeof(arr[0]);
>for(i=0;i{
>for(j=i;j{
>p=arr[j]-arr[i];
>if((p-diff)>0)
>diff=p;
>}
>}
>return diff;
> }
> vishal@ubuntu:~/progs/c\ 11:04:40 AM >$ gcc alg.c -Wall
>
>
> On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa 
> wrote:
> > actually u r passing arr,and receiving arr[] which actually receives the
> > first element address. So arr will be a reference to first address. so
> its
> > size will be 4  bytes and arr size will also be 4 bytes. so ur len
> contains
> > only 1. so ur loop runs only once.i hope it clears.
> >
> > On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh 
> wrote:
> >>
> >> still it's not working
> >>
> >> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao 
> wrote:
> >>>
> >>> int maxdiff(int );
> >>> int maxdiff(int arr[]);
> >>> The signatures of  maxdiff function are  not the same.
> >>>
> >>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh 
> >>> wrote:
> 
>  this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
>  integer from pointer without a cast) . Please explain the reasons.
> 
> 
>  #include
>  #include
>  int maxdiff(int );
>  main()
>  {
>    int p,arr[]={2,4,1,6,23,4};
>    p=maxdiff(arr);
>    printf("\n MAX Diff is \t %d",p);
>    getch();
>    }
>  int maxdiff(int arr[])
>  {
>  int diff=0,len,i,j;
>  unsigned p;
>  len=sizeof(arr)/sizeof(arr[0]);
>  for(i=0;i  {
>    for(j=i;j    {
>   p=arr[j]-arr[i];
>   if((p-diff)>0)
>   diff=p;
>    }
>  }
>  return diff;
>  }
> 
>  --
>  with regards,
>  Ashwini kumar singh
>  ECE Final yr.
>  NIT Allahabad
> 
> 
>  --
>  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.
> >>
> >>
> >>
> >> --
> >> with regards,
> >> Ashwini kumar singh
> >> ECE Final yr.
> >> MNNIT Allahabad
> >> Mobile: 7505519402
> >>
> >> --
> >> 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.
> >
> >
> >
> > --
> > Varun Pahwa
> > B.Tech (IT)
> > 7th Sem.
> > Indian Institute of Information Technology Allahabad.
> > Ph : 09793899112 ,08011820777
> > Official Email :: rit2008...@iiita.ac.in
> > Another Email :: varunpahwa.ii...@gmail.com
> >
> > People who fail to plan are those who plan to fail.
> >
> > --
> > 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 unsubscr

Re: [algogeeks] please explain

2011-06-30 Thread Vishal Thanki
Rujin is right, here is the code which compiles..

vishal@ubuntu:~/progs/c\ 11:04:37 AM >$ cat alg.c
#include
int maxdiff(int arr[]);
int main()
{
int p,arr[]={2,4,1,6,23,4};
p=maxdiff(arr);
printf("\n MAX Diff is \t %d",p);
return 0;
}
int maxdiff(int arr[])
{
int diff=0,len,i,j;
unsigned p;
len=sizeof(arr)/sizeof(arr[0]);
for(i=0;i0)
diff=p;
}
}
return diff;
}
vishal@ubuntu:~/progs/c\ 11:04:40 AM >$ gcc alg.c -Wall


On Fri, Jul 1, 2011 at 7:20 AM, varun pahwa  wrote:
> actually u r passing arr,and receiving arr[] which actually receives the
> first element address. So arr will be a reference to first address. so its
> size will be 4  bytes and arr size will also be 4 bytes. so ur len contains
> only 1. so ur loop runs only once.i hope it clears.
>
> On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh  wrote:
>>
>> still it's not working
>>
>> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao  wrote:
>>>
>>> int maxdiff(int );
>>> int maxdiff(int arr[]);
>>> The signatures of  maxdiff function are  not the same.
>>>
>>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh 
>>> wrote:

 this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
 integer from pointer without a cast) . Please explain the reasons.


 #include
 #include
 int maxdiff(int );
 main()
 {
   int p,arr[]={2,4,1,6,23,4};
   p=maxdiff(arr);
   printf("\n MAX Diff is \t %d",p);
   getch();
   }
 int maxdiff(int arr[])
 {
     int diff=0,len,i,j;
     unsigned p;
     len=sizeof(arr)/sizeof(arr[0]);
     for(i=0;i>>>     {
   for(j=i;j>>>   {
  p=arr[j]-arr[i];
  if((p-diff)>0)
  diff=p;
   }
     }
     return diff;
     }

 --
 with regards,
 Ashwini kumar singh
 ECE Final yr.
 NIT Allahabad


 --
 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.
>>
>>
>>
>> --
>> with regards,
>> Ashwini kumar singh
>> ECE Final yr.
>> MNNIT Allahabad
>> Mobile: 7505519402
>>
>> --
>> 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.
>
>
>
> --
> Varun Pahwa
> B.Tech (IT)
> 7th Sem.
> Indian Institute of Information Technology Allahabad.
> Ph : 09793899112 ,08011820777
> Official Email :: rit2008...@iiita.ac.in
> Another Email :: varunpahwa.ii...@gmail.com
>
> People who fail to plan are those who plan to fail.
>
> --
> 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] please explain

2011-06-30 Thread varun pahwa
actually u r passing arr,and receiving arr[] which actually receives the
first element address. So arr will be a reference to first address. so its
size will be 4  bytes and arr size will also be 4 bytes. so ur len contains
only 1. so ur loop runs only once.i hope it clears.

On Thu, Jun 30, 2011 at 4:49 PM, ashwini singh  wrote:

> still it's not working
>
> On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao  wrote:
>
>> int maxdiff(int );
>> int maxdiff(int arr[]);
>>
>> The signatures of  maxdiff function are  not the same.
>>
>>
>> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh wrote:
>>
>>> this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
>>> integer from pointer without a cast) . Please explain the reasons.
>>>
>>>
>>> #include
>>> #include
>>> int maxdiff(int );
>>> main()
>>> {
>>>   int p,arr[]={2,4,1,6,23,4};
>>>   p=maxdiff(arr);
>>>   printf("\n MAX Diff is \t %d",p);
>>>   getch();
>>>   }
>>> int maxdiff(int arr[])
>>> {
>>> int diff=0,len,i,j;
>>> unsigned p;
>>> len=sizeof(arr)/sizeof(arr[0]);
>>> for(i=0;i>> {
>>>   for(j=i;j>>   {
>>>  p=arr[j]-arr[i];
>>>  if((p-diff)>0)
>>>  diff=p;
>>>   }
>>> }
>>> return diff;
>>> }
>>>
>>> --
>>> with regards,
>>> Ashwini kumar singh
>>> ECE Final yr.
>>> NIT Allahabad
>>> **
>>>
>>>  --
>>> 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.
>>
>
>
>
> --
> with regards,
> Ashwini kumar singh
> ECE Final yr.
> MNNIT Allahabad
> *Mobile: *7505519402
>
>
>  --
> 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.
>



-- 
Varun Pahwa
B.Tech (IT)
7th Sem.
Indian Institute of Information Technology Allahabad.
Ph : 09793899112 ,08011820777
Official Email :: rit2008...@iiita.ac.in
Another Email :: varunpahwa.ii...@gmail.com

People who fail to plan are those who plan to fail.

-- 
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] please explain

2011-06-30 Thread ashwini singh
still it's not working

On Thu, Jun 30, 2011 at 4:42 PM, Rujin Cao  wrote:

> int maxdiff(int );
> int maxdiff(int arr[]);
>
> The signatures of  maxdiff function are  not the same.
>
>
> On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh  wrote:
>
>> this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
>> integer from pointer without a cast) . Please explain the reasons.
>>
>>
>> #include
>> #include
>> int maxdiff(int );
>> main()
>> {
>>   int p,arr[]={2,4,1,6,23,4};
>>   p=maxdiff(arr);
>>   printf("\n MAX Diff is \t %d",p);
>>   getch();
>>   }
>> int maxdiff(int arr[])
>> {
>> int diff=0,len,i,j;
>> unsigned p;
>> len=sizeof(arr)/sizeof(arr[0]);
>> for(i=0;i> {
>>   for(j=i;j>   {
>>  p=arr[j]-arr[i];
>>  if((p-diff)>0)
>>  diff=p;
>>   }
>> }
>> return diff;
>> }
>>
>> --
>> with regards,
>> Ashwini kumar singh
>> ECE Final yr.
>> NIT Allahabad
>> **
>>
>>  --
>> 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.
>



-- 
with regards,
Ashwini kumar singh
ECE Final yr.
MNNIT Allahabad
*Mobile: *7505519402

-- 
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] please explain

2011-06-30 Thread Rujin Cao
int maxdiff(int );
int maxdiff(int arr[]);

The signatures of  maxdiff function are  not the same.


On Fri, Jul 1, 2011 at 6:53 AM, ashwini singh  wrote:

> this code gives an error ([Warning] passing arg 1 of `maxdiff' makes
> integer from pointer without a cast) . Please explain the reasons.
>
>
> #include
> #include
> int maxdiff(int );
> main()
> {
>   int p,arr[]={2,4,1,6,23,4};
>   p=maxdiff(arr);
>   printf("\n MAX Diff is \t %d",p);
>   getch();
>   }
> int maxdiff(int arr[])
> {
> int diff=0,len,i,j;
> unsigned p;
> len=sizeof(arr)/sizeof(arr[0]);
> for(i=0;i {
>   for(j=i;j   {
>  p=arr[j]-arr[i];
>  if((p-diff)>0)
>  diff=p;
>   }
> }
> return diff;
> }
>
> --
> with regards,
> Ashwini kumar singh
> ECE Final yr.
> NIT Allahabad
> **
>
>  --
> 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] please explain

2011-06-30 Thread ashwini singh
this code gives an error ([Warning] passing arg 1 of `maxdiff' makes integer
from pointer without a cast) . Please explain the reasons.


#include
#include
int maxdiff(int );
main()
{
  int p,arr[]={2,4,1,6,23,4};
  p=maxdiff(arr);
  printf("\n MAX Diff is \t %d",p);
  getch();
  }
int maxdiff(int arr[])
{
int diff=0,len,i,j;
unsigned p;
len=sizeof(arr)/sizeof(arr[0]);
for(i=0;i0)
 diff=p;
  }
}
return diff;
}

-- 
with regards,
Ashwini kumar singh
ECE Final yr.
NIT Allahabad
**

-- 
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] Please explain the output

2011-06-23 Thread rajeev bharshetty
#a is the replacement sequence which is substituted in the printf statement
The statements
#define power(a) #a
printf("%d",power(a));

is substituted as

printf("%d","a");

it is replaced with the string literal "a" . then *power(a) is converted as
value at that string literal address.

Hope this solves the problem :)
--
Rajeev N B

I Blog @ www.opensourcemania.co.cc

On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla wrote:

> #include
> #define power(a) #a
> int main()
> {
>  printf("%d",*power(432));
>   return 0;
> }
>
>
> ans is 52 on gcc. Explain plss
>
> --
>   best wishes!!
> Vaibhav Shukla
> DU-MCA
>
>  --
> 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] Please explain the output

2011-06-23 Thread vaibhav shukla
hmm i got it.thnx

On Thu, Jun 23, 2011 at 4:05 PM, Piyush Sinha wrote:

> printf("%d",*power(432)) will expand as
>
> *printf("%d", *"432")*
>
> "432" represents here a string and *"432" is pointing to the first string
> literal i.e 4 whose ascii value is 52..hence the output is 52
>
>
> On Thu, Jun 23, 2011 at 4:02 PM, Shachindra A C wrote:
>
>>  #include
>> #define power(a) #a
>> int main()
>> {
>>  printf("%d",*power(432));
>>   return 0;
>> }
>>
>> the printf statement, after preprocessing, will look like
>> printf("%d",*"432");
>>
>> so, when u print the value at the first position of the string, 52, which
>> is the ascii value of 4, will be printed.
>>
>> On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla 
>> wrote:
>>
>>> #include
>>> #define power(a) #a
>>> int main()
>>> {
>>>  printf("%d",*power(432));
>>>   return 0;
>>> }
>>>
>>>
>>> ans is 52 on gcc. Explain plss
>>>
>>> --
>>>   best wishes!!
>>> Vaibhav Shukla
>>> DU-MCA
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> Regards,
>> Shachindra A C
>>
>> --
>> 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.
>>
>
>
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-8792136657*
> *+91-7483122727*
> *https://www.facebook.com/profile.php?id=10655377926 *
>
>  --
> 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.
>



-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

-- 
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] Please explain the output

2011-06-23 Thread Piyush Sinha
printf("%d",*power(432)) will expand as

*printf("%d", *"432")*

"432" represents here a string and *"432" is pointing to the first string
literal i.e 4 whose ascii value is 52..hence the output is 52


On Thu, Jun 23, 2011 at 4:02 PM, Shachindra A C wrote:

>  #include
> #define power(a) #a
> int main()
> {
>  printf("%d",*power(432));
>   return 0;
> }
>
> the printf statement, after preprocessing, will look like
> printf("%d",*"432");
>
> so, when u print the value at the first position of the string, 52, which
> is the ascii value of 4, will be printed.
>
> On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla 
> wrote:
>
>> #include
>> #define power(a) #a
>> int main()
>> {
>>  printf("%d",*power(432));
>>   return 0;
>> }
>>
>>
>> ans is 52 on gcc. Explain plss
>>
>> --
>>   best wishes!!
>> Vaibhav Shukla
>> DU-MCA
>>
>> --
>> 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.
>>
>
>
>
> --
> Regards,
> Shachindra A C
>
> --
> 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.
>



-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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] Please explain the output

2011-06-23 Thread Shachindra A C
#include
#define power(a) #a
int main()
{
 printf("%d",*power(432));
  return 0;
}

the printf statement, after preprocessing, will look like
printf("%d",*"432");

so, when u print the value at the first position of the string, 52, which is
the ascii value of 4, will be printed.

On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla wrote:

> #include
> #define power(a) #a
> int main()
> {
>  printf("%d",*power(432));
>   return 0;
> }
>
>
> ans is 52 on gcc. Explain plss
>
> --
>   best wishes!!
> Vaibhav Shukla
> DU-MCA
>
>  --
> 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.
>



-- 
Regards,
Shachindra A C

-- 
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] Please explain the output

2011-06-23 Thread vaibhav shukla
#include
#define power(a) #a
int main()
{
 printf("%d",*power(432));
  return 0;
}


ans is 52 on gcc. Explain plss

-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

-- 
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] Please explain this problem

2011-06-12 Thread keyan karthi
@saurabh: ya u checked tat... then ur logic seems rite..
On Sun, Jun 12, 2011 at 2:27 PM, nicks  wrote:

> @keyan...that solves my problem...got AC...thanks :)
>
>
> On Sun, Jun 12, 2011 at 1:15 AM, nicks  wrote:
>
>> forgot to attach the code...here is the modified code..
>>
>> #include
>> #include
>> #include
>> #include
>> #include
>>
>> using namespace std;
>>
>> int main()
>> {
>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>> scanf("%d",&num);
>> vector val,a1,a2;
>> for(i=0;i> {
>> scanf("%d",&t);
>> val.push_back(t);
>> }
>> for(i=0;i> {
>> a=val[i];
>> for(j=0;j> {
>> b=val[j];
>> for(k=0;k> {
>> c=val[k];
>> t=a*b+c;
>> a1.push_back(t);
>> }
>> }
>> }
>> for(i=0;i> {
>> d=val[i];
>> for(j=0;j> {
>> e=val[j];
>> for(k=0;k> {
>> f=val[k];
>> t=(f+e)*d;
>> a2.push_back(t);
>> }
>> }
>> }
>>
>> sort(a2.begin(),a2.end());
>> vector::iterator itr;
>> for(itr=a1.begin();itr!=a1.end();itr++)
>> {
>>  value=*itr;
>>  //ans+=count(a2.begin(),a2.end(),value);
>>
>>  
>> ans+=upper_bound(a2.begin(),a2.end(),value)-lower_bound(a2.begin(),a2.end(),value);
>> }
>>
>> printf("%d",ans);
>> return 0;
>> }
>>
>>
>>
>>
>>
>>
>> On Sun, Jun 12, 2011 at 1:07 AM, nicks wrote:
>>
>>> @keyan..your advice was really very helpful...the time limit has come
>>> under control ...1.4s but now i am getting WA though my code is giving right
>>> ans for the test cases...can you plz help me in figuring out where it fails
>>> ..
>>>
>>>
>>> On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi <
>>> keyankarthi1...@gmail.com> wrote:
>>>

 hint: u ve commented some vital part of ur code ;)

 On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh wrote:

>
> I did used the library functions but I am getting sigsegv after 0.03
> s.I cant understand why?I am presuming sumthing wrong about the
> implemenatation of bsearch?
> I am assuming bsearch is returning a pointer to the first found
> element.
>
> On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi <
> keyankarthi1...@gmail.com> wrote:
>
>> upper_bound and lower_bound does a binary search to get count of alike
>> terms.. which u tend to sum of to get the ans..
>> out of the two arrays, u need to sort one array.. this will be teh
>> vector in which u do the binary search wit every element of un sorted
>> array..
>> this is the approach i used... :) hope this helps...
>>
>> the above functions defined in "algorithm"
>>
>>
>> On Sun, Jun 12, 2011 at 12:34 PM, nicks 
>> wrote:
>>
>>> and here is my code I'm Getting TLE i tried to implement binary
>>> search but failed bcoz how will i be able to trace the value from one 
>>> vector
>>> into another vector if there are any multiple occureneces of any value(i
>>> mean i have count them).in this code i i have used count of 
>>> algorithm
>>> which may be expensive...suggest a better way plz...thnx in advance !!
>>>
>>>
>>>
>>> #include
>>> #include
>>> #include
>>> #include
>>> #include
>>> using namespace std;
>>> int main()
>>> {
>>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>>> scanf("%d",&num);
>>> vector val,a1,a2;
>>> for(i=0;i>> {
>>> scanf("%d",&t);
>>> val.push_back(t);
>>> }
>>> for(i=0;i>> {
>>> a=val[i];
>>> for(j=0;j>> {
>>> b=val[j];
>>> for(k=0;k>> {
>>> c=val[k];
>>> t=a*b+c;
>>> a1.push_back(t);
>>> }
>>> }
>>> }
>>> for(i=0;i>> {
>>> d=val[i];
>>> for(j=0;j>> {
>>> e=val[j];
>>> for(k=0;k>> {
>>> f=val[k];
>>> t=(f+e)*d;
>>> a2.push_back(t);
>>> }
>>> }
>>> }
>>>
>>> vector::iterator itr;
>>> for(itr=a1.begin();itr!=a1.end();itr++)
>>> {
>>>  value=*itr;
>>>  ans+=count(a2.begin(),a2.end(),value);
>>> }
>>>
>>> printf("%d\n",ans);
>>> return 0;
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>   On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh <
>>> saurab...@gmail.com> wrote:
>>>
>

Re: [algogeeks] Please explain this problem

2011-06-12 Thread nicks
@keyan...that solves my problem...got AC...thanks :)

On Sun, Jun 12, 2011 at 1:15 AM, nicks  wrote:

> forgot to attach the code...here is the modified code..
>
> #include
> #include
> #include
> #include
> #include
>
> using namespace std;
>
> int main()
> {
> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
> scanf("%d",&num);
> vector val,a1,a2;
> for(i=0;i {
> scanf("%d",&t);
> val.push_back(t);
> }
> for(i=0;i {
> a=val[i];
> for(j=0;j {
> b=val[j];
> for(k=0;k {
> c=val[k];
> t=a*b+c;
> a1.push_back(t);
> }
> }
> }
> for(i=0;i {
> d=val[i];
> for(j=0;j {
> e=val[j];
> for(k=0;k {
> f=val[k];
> t=(f+e)*d;
> a2.push_back(t);
> }
> }
> }
>
> sort(a2.begin(),a2.end());
> vector::iterator itr;
> for(itr=a1.begin();itr!=a1.end();itr++)
> {
>  value=*itr;
>  //ans+=count(a2.begin(),a2.end(),value);
>
>  
> ans+=upper_bound(a2.begin(),a2.end(),value)-lower_bound(a2.begin(),a2.end(),value);
> }
>
> printf("%d",ans);
> return 0;
> }
>
>
>
>
>
>
> On Sun, Jun 12, 2011 at 1:07 AM, nicks  wrote:
>
>> @keyan..your advice was really very helpful...the time limit has come
>> under control ...1.4s but now i am getting WA though my code is giving right
>> ans for the test cases...can you plz help me in figuring out where it fails
>> ..
>>
>>
>> On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi > > wrote:
>>
>>>
>>> hint: u ve commented some vital part of ur code ;)
>>>
>>> On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh wrote:
>>>

 I did used the library functions but I am getting sigsegv after 0.03 s.I
 cant understand why?I am presuming sumthing wrong about the implemenatation
 of bsearch?
 I am assuming bsearch is returning a pointer to the first found element.


 On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi <
 keyankarthi1...@gmail.com> wrote:

> upper_bound and lower_bound does a binary search to get count of alike
> terms.. which u tend to sum of to get the ans..
> out of the two arrays, u need to sort one array.. this will be teh
> vector in which u do the binary search wit every element of un sorted
> array..
> this is the approach i used... :) hope this helps...
>
> the above functions defined in "algorithm"
>
>
> On Sun, Jun 12, 2011 at 12:34 PM, nicks wrote:
>
>> and here is my code I'm Getting TLE i tried to implement binary
>> search but failed bcoz how will i be able to trace the value from one 
>> vector
>> into another vector if there are any multiple occureneces of any value(i
>> mean i have count them).in this code i i have used count of algorithm
>> which may be expensive...suggest a better way plz...thnx in advance !!
>>
>>
>>
>> #include
>> #include
>> #include
>> #include
>> #include
>> using namespace std;
>> int main()
>> {
>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>> scanf("%d",&num);
>> vector val,a1,a2;
>> for(i=0;i> {
>> scanf("%d",&t);
>> val.push_back(t);
>> }
>> for(i=0;i> {
>> a=val[i];
>> for(j=0;j> {
>> b=val[j];
>> for(k=0;k> {
>> c=val[k];
>> t=a*b+c;
>> a1.push_back(t);
>> }
>> }
>> }
>> for(i=0;i> {
>> d=val[i];
>> for(j=0;j> {
>> e=val[j];
>> for(k=0;k> {
>> f=val[k];
>> t=(f+e)*d;
>> a2.push_back(t);
>> }
>> }
>> }
>>
>> vector::iterator itr;
>> for(itr=a1.begin();itr!=a1.end();itr++)
>> {
>>  value=*itr;
>>  ans+=count(a2.begin(),a2.end(),value);
>> }
>>
>> printf("%d\n",ans);
>> return 0;
>> }
>>
>>
>>
>>
>>
>>
>>   On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh <
>> saurab...@gmail.com> wrote:
>>
>>>
>>> OK here is my code
>>> #include
>>> #include
>>> #include
>>> using namespace std;
>>> int compareints (const void * a, const void * b)
>>> {
>>>   return ( *(long*)a - *(long*)b );
>>> }
>>>
>>>
>>> int main()
>>> {
>>> int n,s[101],a,b,c,d,e,f;
>>> long p1

Re: [algogeeks] Please explain this problem

2011-06-12 Thread saurabh singh
where I am I dividing by 0?
i have used the check
if(s[l])
p1[k++]=(s[i]+s[j])*s[l];
On Sun, Jun 12, 2011 at 1:58 PM, keyan karthi wrote:

> @saurabh,nick: u cant divide by 0.. u need to check it while generating the
> array..
>
> i used somethin like this...
>
>
>1. void fun(int n)
>2. {
>3. int a,b,cl;
>4. for(a=0;a5. {
>6. for(b=0;b7. {
>8. for(cl=0;cl9. {
>10. v.push_back((inp[a]*inp[b])+inp[cl]);
>11. if(inp[cl])
>12. c.push_back(inp[cl]*(inp[a]+inp[b]));
>13. }
>14. }
>15. }
>16. }
>
> u cant divide by 0.. tats why u get tat runtime error... fix it :)
>
>
> On Sun, Jun 12, 2011 at 1:52 PM, saurabh singh wrote:
>
>> I am trying really hard to get this one fixed,still cant find any
>> problem..:-(
>>
>>
>> On Sun, Jun 12, 2011 at 1:45 PM, nicks wrote:
>>
>>> forgot to attach the code...here is the modified code..
>>>
>>> #include
>>> #include
>>> #include
>>> #include
>>> #include
>>>
>>> using namespace std;
>>>
>>> int main()
>>> {
>>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>>> scanf("%d",&num);
>>> vector val,a1,a2;
>>> for(i=0;i>> {
>>> scanf("%d",&t);
>>> val.push_back(t);
>>> }
>>> for(i=0;i>> {
>>> a=val[i];
>>> for(j=0;j>> {
>>> b=val[j];
>>> for(k=0;k>> {
>>> c=val[k];
>>> t=a*b+c;
>>> a1.push_back(t);
>>> }
>>> }
>>> }
>>> for(i=0;i>> {
>>> d=val[i];
>>> for(j=0;j>> {
>>> e=val[j];
>>> for(k=0;k>> {
>>> f=val[k];
>>> t=(f+e)*d;
>>> a2.push_back(t);
>>> }
>>> }
>>> }
>>>
>>> sort(a2.begin(),a2.end());
>>> vector::iterator itr;
>>> for(itr=a1.begin();itr!=a1.end();itr++)
>>> {
>>>  value=*itr;
>>>  //ans+=count(a2.begin(),a2.end(),value);
>>>
>>>  
>>> ans+=upper_bound(a2.begin(),a2.end(),value)-lower_bound(a2.begin(),a2.end(),value);
>>> }
>>>
>>> printf("%d",ans);
>>> return 0;
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Sun, Jun 12, 2011 at 1:07 AM, nicks wrote:
>>>
 @keyan..your advice was really very helpful...the time limit has come
 under control ...1.4s but now i am getting WA though my code is giving 
 right
 ans for the test cases...can you plz help me in figuring out where it fails
 ..


 On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi <
 keyankarthi1...@gmail.com> wrote:

>
> hint: u ve commented some vital part of ur code ;)
>
> On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh 
> wrote:
>
>>
>> I did used the library functions but I am getting sigsegv after 0.03
>> s.I cant understand why?I am presuming sumthing wrong about the
>> implemenatation of bsearch?
>> I am assuming bsearch is returning a pointer to the first found
>> element.
>>
>> On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi <
>> keyankarthi1...@gmail.com> wrote:
>>
>>> upper_bound and lower_bound does a binary search to get count of
>>> alike terms.. which u tend to sum of to get the ans..
>>> out of the two arrays, u need to sort one array.. this will be teh
>>> vector in which u do the binary search wit every element of un sorted
>>> array..
>>> this is the approach i used... :) hope this helps...
>>>
>>> the above functions defined in "algorithm"
>>>
>>>
>>> On Sun, Jun 12, 2011 at 12:34 PM, nicks 
>>> wrote:
>>>
 and here is my code I'm Getting TLE i tried to implement binary
 search but failed bcoz how will i be able to trace the value from one 
 vector
 into another vector if there are any multiple occureneces of any 
 value(i
 mean i have count them).in this code i i have used count of 
 algorithm
 which may be expensive...suggest a better way plz...thnx in advance !!



 #include
 #include
 #include
 #include
 #include
 using namespace std;
 int main()
 {
 int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
 scanf("%d",&num);
 vector val,a1,a2;
 for(i=0;i>>> {
 scanf("%d",&t);
 val.push_back(t);
 }
 for(i=0;i>>> {
 a=val[i];
 for(j=0;j>>> {
 b=val[j];
 for(k=0;k>>> {
 c=val[k];
 t=a*b+c;
 a1.push_back(t);
 }
 }
 }
 for(i=0;

Re: [algogeeks] Please explain this problem

2011-06-12 Thread keyan karthi
@saurabh,nick: u cant divide by 0.. u need to check it while generating the
array..

i used somethin like this...


   1. void fun(int n)
   2. {
   3. int a,b,cl;
   4. for(a=0;a wrote:

> I am trying really hard to get this one fixed,still cant find any
> problem..:-(
>
>
> On Sun, Jun 12, 2011 at 1:45 PM, nicks  wrote:
>
>> forgot to attach the code...here is the modified code..
>>
>> #include
>> #include
>> #include
>> #include
>> #include
>>
>> using namespace std;
>>
>> int main()
>> {
>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>> scanf("%d",&num);
>> vector val,a1,a2;
>> for(i=0;i> {
>> scanf("%d",&t);
>> val.push_back(t);
>> }
>> for(i=0;i> {
>> a=val[i];
>> for(j=0;j> {
>> b=val[j];
>> for(k=0;k> {
>> c=val[k];
>> t=a*b+c;
>> a1.push_back(t);
>> }
>> }
>> }
>> for(i=0;i> {
>> d=val[i];
>> for(j=0;j> {
>> e=val[j];
>> for(k=0;k> {
>> f=val[k];
>> t=(f+e)*d;
>> a2.push_back(t);
>> }
>> }
>> }
>>
>> sort(a2.begin(),a2.end());
>> vector::iterator itr;
>> for(itr=a1.begin();itr!=a1.end();itr++)
>> {
>>  value=*itr;
>>  //ans+=count(a2.begin(),a2.end(),value);
>>
>>  
>> ans+=upper_bound(a2.begin(),a2.end(),value)-lower_bound(a2.begin(),a2.end(),value);
>> }
>>
>> printf("%d",ans);
>> return 0;
>> }
>>
>>
>>
>>
>>
>>
>> On Sun, Jun 12, 2011 at 1:07 AM, nicks wrote:
>>
>>> @keyan..your advice was really very helpful...the time limit has come
>>> under control ...1.4s but now i am getting WA though my code is giving right
>>> ans for the test cases...can you plz help me in figuring out where it fails
>>> ..
>>>
>>>
>>> On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi <
>>> keyankarthi1...@gmail.com> wrote:
>>>

 hint: u ve commented some vital part of ur code ;)

 On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh wrote:

>
> I did used the library functions but I am getting sigsegv after 0.03
> s.I cant understand why?I am presuming sumthing wrong about the
> implemenatation of bsearch?
> I am assuming bsearch is returning a pointer to the first found
> element.
>
> On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi <
> keyankarthi1...@gmail.com> wrote:
>
>> upper_bound and lower_bound does a binary search to get count of alike
>> terms.. which u tend to sum of to get the ans..
>> out of the two arrays, u need to sort one array.. this will be teh
>> vector in which u do the binary search wit every element of un sorted
>> array..
>> this is the approach i used... :) hope this helps...
>>
>> the above functions defined in "algorithm"
>>
>>
>> On Sun, Jun 12, 2011 at 12:34 PM, nicks 
>> wrote:
>>
>>> and here is my code I'm Getting TLE i tried to implement binary
>>> search but failed bcoz how will i be able to trace the value from one 
>>> vector
>>> into another vector if there are any multiple occureneces of any value(i
>>> mean i have count them).in this code i i have used count of 
>>> algorithm
>>> which may be expensive...suggest a better way plz...thnx in advance !!
>>>
>>>
>>>
>>> #include
>>> #include
>>> #include
>>> #include
>>> #include
>>> using namespace std;
>>> int main()
>>> {
>>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>>> scanf("%d",&num);
>>> vector val,a1,a2;
>>> for(i=0;i>> {
>>> scanf("%d",&t);
>>> val.push_back(t);
>>> }
>>> for(i=0;i>> {
>>> a=val[i];
>>> for(j=0;j>> {
>>> b=val[j];
>>> for(k=0;k>> {
>>> c=val[k];
>>> t=a*b+c;
>>> a1.push_back(t);
>>> }
>>> }
>>> }
>>> for(i=0;i>> {
>>> d=val[i];
>>> for(j=0;j>> {
>>> e=val[j];
>>> for(k=0;k>> {
>>> f=val[k];
>>> t=(f+e)*d;
>>> a2.push_back(t);
>>> }
>>> }
>>> }
>>>
>>> vector::iterator itr;
>>> for(itr=a1.begin();itr!=a1.end();itr++)
>>> {
>>>  value=*itr;
>>>  ans+=count(a2.begin(),a2.end(),value);
>>> }
>>>
>>> printf("%d\n",ans);
>>> return 0;
>>> }
>>>
>>>
>>>
>>>
>>>
>>

Re: [algogeeks] Please explain this problem

2011-06-12 Thread saurabh singh
I am trying really hard to get this one fixed,still cant find any
problem..:-(

On Sun, Jun 12, 2011 at 1:45 PM, nicks  wrote:

> forgot to attach the code...here is the modified code..
>
> #include
> #include
> #include
> #include
> #include
>
> using namespace std;
>
> int main()
> {
> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
> scanf("%d",&num);
> vector val,a1,a2;
> for(i=0;i {
> scanf("%d",&t);
> val.push_back(t);
> }
> for(i=0;i {
> a=val[i];
> for(j=0;j {
> b=val[j];
> for(k=0;k {
> c=val[k];
> t=a*b+c;
> a1.push_back(t);
> }
> }
> }
> for(i=0;i {
> d=val[i];
> for(j=0;j {
> e=val[j];
> for(k=0;k {
> f=val[k];
> t=(f+e)*d;
> a2.push_back(t);
> }
> }
> }
>
> sort(a2.begin(),a2.end());
> vector::iterator itr;
> for(itr=a1.begin();itr!=a1.end();itr++)
> {
>  value=*itr;
>  //ans+=count(a2.begin(),a2.end(),value);
>
>  
> ans+=upper_bound(a2.begin(),a2.end(),value)-lower_bound(a2.begin(),a2.end(),value);
> }
>
> printf("%d",ans);
> return 0;
> }
>
>
>
>
>
>
> On Sun, Jun 12, 2011 at 1:07 AM, nicks  wrote:
>
>> @keyan..your advice was really very helpful...the time limit has come
>> under control ...1.4s but now i am getting WA though my code is giving right
>> ans for the test cases...can you plz help me in figuring out where it fails
>> ..
>>
>>
>> On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi > > wrote:
>>
>>>
>>> hint: u ve commented some vital part of ur code ;)
>>>
>>> On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh wrote:
>>>

 I did used the library functions but I am getting sigsegv after 0.03 s.I
 cant understand why?I am presuming sumthing wrong about the implemenatation
 of bsearch?
 I am assuming bsearch is returning a pointer to the first found element.


 On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi <
 keyankarthi1...@gmail.com> wrote:

> upper_bound and lower_bound does a binary search to get count of alike
> terms.. which u tend to sum of to get the ans..
> out of the two arrays, u need to sort one array.. this will be teh
> vector in which u do the binary search wit every element of un sorted
> array..
> this is the approach i used... :) hope this helps...
>
> the above functions defined in "algorithm"
>
>
> On Sun, Jun 12, 2011 at 12:34 PM, nicks wrote:
>
>> and here is my code I'm Getting TLE i tried to implement binary
>> search but failed bcoz how will i be able to trace the value from one 
>> vector
>> into another vector if there are any multiple occureneces of any value(i
>> mean i have count them).in this code i i have used count of algorithm
>> which may be expensive...suggest a better way plz...thnx in advance !!
>>
>>
>>
>> #include
>> #include
>> #include
>> #include
>> #include
>> using namespace std;
>> int main()
>> {
>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>> scanf("%d",&num);
>> vector val,a1,a2;
>> for(i=0;i> {
>> scanf("%d",&t);
>> val.push_back(t);
>> }
>> for(i=0;i> {
>> a=val[i];
>> for(j=0;j> {
>> b=val[j];
>> for(k=0;k> {
>> c=val[k];
>> t=a*b+c;
>> a1.push_back(t);
>> }
>> }
>> }
>> for(i=0;i> {
>> d=val[i];
>> for(j=0;j> {
>> e=val[j];
>> for(k=0;k> {
>> f=val[k];
>> t=(f+e)*d;
>> a2.push_back(t);
>> }
>> }
>> }
>>
>> vector::iterator itr;
>> for(itr=a1.begin();itr!=a1.end();itr++)
>> {
>>  value=*itr;
>>  ans+=count(a2.begin(),a2.end(),value);
>> }
>>
>> printf("%d\n",ans);
>> return 0;
>> }
>>
>>
>>
>>
>>
>>
>>   On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh <
>> saurab...@gmail.com> wrote:
>>
>>>
>>> OK here is my code
>>> #include
>>> #include
>>> #include
>>> using namespace std;
>>> int compareints (const void * a, const void * b)
>>> {
>>>   return ( *(long*)a - *(long*)b );
>>> }
>>>
>>>
>>> int main()
>>> {
>>> int n,s[101],a,

Re: [algogeeks] Please explain this problem

2011-06-12 Thread nicks
forgot to attach the code...here is the modified code..

#include
#include
#include
#include
#include

using namespace std;

int main()
{
int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
scanf("%d",&num);
vector val,a1,a2;
for(i=0;i::iterator itr;
for(itr=a1.begin();itr!=a1.end();itr++)
{
 value=*itr;
 //ans+=count(a2.begin(),a2.end(),value);

 
ans+=upper_bound(a2.begin(),a2.end(),value)-lower_bound(a2.begin(),a2.end(),value);
}

printf("%d",ans);
return 0;
}






On Sun, Jun 12, 2011 at 1:07 AM, nicks  wrote:

> @keyan..your advice was really very helpful...the time limit has come under
> control ...1.4s but now i am getting WA though my code is giving right ans
> for the test cases...can you plz help me in figuring out where it fails ..
>
>
> On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi 
> wrote:
>
>>
>> hint: u ve commented some vital part of ur code ;)
>>
>> On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh wrote:
>>
>>>
>>> I did used the library functions but I am getting sigsegv after 0.03 s.I
>>> cant understand why?I am presuming sumthing wrong about the implemenatation
>>> of bsearch?
>>> I am assuming bsearch is returning a pointer to the first found element.
>>>
>>> On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi <
>>> keyankarthi1...@gmail.com> wrote:
>>>
 upper_bound and lower_bound does a binary search to get count of alike
 terms.. which u tend to sum of to get the ans..
 out of the two arrays, u need to sort one array.. this will be teh
 vector in which u do the binary search wit every element of un sorted
 array..
 this is the approach i used... :) hope this helps...

 the above functions defined in "algorithm"


 On Sun, Jun 12, 2011 at 12:34 PM, nicks wrote:

> and here is my code I'm Getting TLE i tried to implement binary
> search but failed bcoz how will i be able to trace the value from one 
> vector
> into another vector if there are any multiple occureneces of any value(i
> mean i have count them).in this code i i have used count of algorithm
> which may be expensive...suggest a better way plz...thnx in advance !!
>
>
>
> #include
> #include
> #include
> #include
> #include
> using namespace std;
> int main()
> {
> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
> scanf("%d",&num);
> vector val,a1,a2;
> for(i=0;i {
> scanf("%d",&t);
> val.push_back(t);
> }
> for(i=0;i {
> a=val[i];
> for(j=0;j {
> b=val[j];
> for(k=0;k {
> c=val[k];
> t=a*b+c;
> a1.push_back(t);
> }
> }
> }
> for(i=0;i {
> d=val[i];
> for(j=0;j {
> e=val[j];
> for(k=0;k {
> f=val[k];
> t=(f+e)*d;
> a2.push_back(t);
> }
> }
> }
>
> vector::iterator itr;
> for(itr=a1.begin();itr!=a1.end();itr++)
> {
>  value=*itr;
>  ans+=count(a2.begin(),a2.end(),value);
> }
>
> printf("%d\n",ans);
> return 0;
> }
>
>
>
>
>
>
>   On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh  > wrote:
>
>>
>> OK here is my code
>> #include
>> #include
>> #include
>> using namespace std;
>> int compareints (const void * a, const void * b)
>> {
>>   return ( *(long*)a - *(long*)b );
>> }
>>
>>
>> int main()
>> {
>> int n,s[101],a,b,c,d,e,f;
>> long p1[19],p2[19];
>> int i,j,k;
>> scanf("%d",&n);
>> for(i=0;i> //sort(s,s+i);
>>  k=0;
>> for(i=0;i> {
>> for(j=0;j> {
>> for(int l=0;l> {
>> if(s[l])
>> p1[k++]=(s[i]+s[j])*s[l];
>> }
>> }
>> }
>> //sort(p1,p1+k);
>> int x=0;
>> for(i=0;i> {
>> for(j=0;j> {
>> for(int l=0;l> {
>> //if(s[l]!=0)
>> p2[x++]=(s[i]*s[j])+s[l];
>> }
>> }
>> }
>> sort(p2,p2+x);
>> long *pItem;
>> long count=0;
>> for(i=0;i> {
>> pItem = (long*) bsearch (&p1[i], p2, x, sizeof (long),
>> compareints);
>> if(pItem){
>>
>> long *tmp=pItem;
>> if(pItem==p2)while

Re: [algogeeks] Please explain this problem

2011-06-12 Thread nicks
@keyan..your advice was really very helpful...the time limit has come under
control ...1.4s but now i am getting WA though my code is giving right ans
for the test cases...can you plz help me in figuring out where it fails ..

On Sun, Jun 12, 2011 at 12:59 AM, keyan karthi wrote:

>
> hint: u ve commented some vital part of ur code ;)
>
> On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh wrote:
>
>>
>> I did used the library functions but I am getting sigsegv after 0.03 s.I
>> cant understand why?I am presuming sumthing wrong about the implemenatation
>> of bsearch?
>> I am assuming bsearch is returning a pointer to the first found element.
>>
>> On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi > > wrote:
>>
>>> upper_bound and lower_bound does a binary search to get count of alike
>>> terms.. which u tend to sum of to get the ans..
>>> out of the two arrays, u need to sort one array.. this will be teh vector
>>> in which u do the binary search wit every element of un sorted array..
>>> this is the approach i used... :) hope this helps...
>>>
>>> the above functions defined in "algorithm"
>>>
>>>
>>> On Sun, Jun 12, 2011 at 12:34 PM, nicks wrote:
>>>
 and here is my code I'm Getting TLE i tried to implement binary
 search but failed bcoz how will i be able to trace the value from one 
 vector
 into another vector if there are any multiple occureneces of any value(i
 mean i have count them).in this code i i have used count of algorithm
 which may be expensive...suggest a better way plz...thnx in advance !!



 #include
 #include
 #include
 #include
 #include
 using namespace std;
 int main()
 {
 int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
 scanf("%d",&num);
 vector val,a1,a2;
 for(i=0;i>>> {
 scanf("%d",&t);
 val.push_back(t);
 }
 for(i=0;i>>> {
 a=val[i];
 for(j=0;j>>> {
 b=val[j];
 for(k=0;k>>> {
 c=val[k];
 t=a*b+c;
 a1.push_back(t);
 }
 }
 }
 for(i=0;i>>> {
 d=val[i];
 for(j=0;j>>> {
 e=val[j];
 for(k=0;k>>> {
 f=val[k];
 t=(f+e)*d;
 a2.push_back(t);
 }
 }
 }

 vector::iterator itr;
 for(itr=a1.begin();itr!=a1.end();itr++)
 {
  value=*itr;
  ans+=count(a2.begin(),a2.end(),value);
 }

 printf("%d\n",ans);
 return 0;
 }






   On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh 
 wrote:

>
> OK here is my code
> #include
> #include
> #include
> using namespace std;
> int compareints (const void * a, const void * b)
> {
>   return ( *(long*)a - *(long*)b );
> }
>
>
> int main()
> {
> int n,s[101],a,b,c,d,e,f;
> long p1[19],p2[19];
> int i,j,k;
> scanf("%d",&n);
> for(i=0;i //sort(s,s+i);
>  k=0;
> for(i=0;i {
> for(j=0;j {
> for(int l=0;l {
> if(s[l])
> p1[k++]=(s[i]+s[j])*s[l];
> }
> }
> }
> //sort(p1,p1+k);
> int x=0;
> for(i=0;i {
> for(j=0;j {
> for(int l=0;l {
> //if(s[l]!=0)
> p2[x++]=(s[i]*s[j])+s[l];
> }
> }
> }
> sort(p2,p2+x);
> long *pItem;
> long count=0;
> for(i=0;i {
> pItem = (long*) bsearch (&p1[i], p2, x, sizeof (long),
> compareints);
> if(pItem){
>
> long *tmp=pItem;
> if(pItem==p2)while(*(tmp)==p1[i]&&tmp count++;tmp++;}
> else
> if(pItem==(p2+(x-1))) {
> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}}
> else{
> tmp++;
> while(*(tmp)==p1[i]&&tmp count++;tmp++;}
>
> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}
> }
>  //count++;
> }
> }
> printf("%ld\n",count);
>
> //for(i=0;i //for(i=0;i return 0;
> }
>
>
> Why is it getting segmentation fault?
>
> --
> You received this message because you are subscribed to the Google

Re: [algogeeks] Please explain this problem

2011-06-12 Thread keyan karthi
hint: u ve commented some vital part of ur code ;)

On Sun, Jun 12, 2011 at 12:46 PM, saurabh singh  wrote:

>
> I did used the library functions but I am getting sigsegv after 0.03 s.I
> cant understand why?I am presuming sumthing wrong about the implemenatation
> of bsearch?
> I am assuming bsearch is returning a pointer to the first found element.
>
> On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi 
> wrote:
>
>> upper_bound and lower_bound does a binary search to get count of alike
>> terms.. which u tend to sum of to get the ans..
>> out of the two arrays, u need to sort one array.. this will be teh vector
>> in which u do the binary search wit every element of un sorted array..
>> this is the approach i used... :) hope this helps...
>>
>> the above functions defined in "algorithm"
>>
>>
>> On Sun, Jun 12, 2011 at 12:34 PM, nicks wrote:
>>
>>> and here is my code I'm Getting TLE i tried to implement binary
>>> search but failed bcoz how will i be able to trace the value from one vector
>>> into another vector if there are any multiple occureneces of any value(i
>>> mean i have count them).in this code i i have used count of algorithm
>>> which may be expensive...suggest a better way plz...thnx in advance !!
>>>
>>>
>>>
>>> #include
>>> #include
>>> #include
>>> #include
>>> #include
>>> using namespace std;
>>> int main()
>>> {
>>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>>> scanf("%d",&num);
>>> vector val,a1,a2;
>>> for(i=0;i>> {
>>> scanf("%d",&t);
>>> val.push_back(t);
>>> }
>>> for(i=0;i>> {
>>> a=val[i];
>>> for(j=0;j>> {
>>> b=val[j];
>>> for(k=0;k>> {
>>> c=val[k];
>>> t=a*b+c;
>>> a1.push_back(t);
>>> }
>>> }
>>> }
>>> for(i=0;i>> {
>>> d=val[i];
>>> for(j=0;j>> {
>>> e=val[j];
>>> for(k=0;k>> {
>>> f=val[k];
>>> t=(f+e)*d;
>>> a2.push_back(t);
>>> }
>>> }
>>> }
>>>
>>> vector::iterator itr;
>>> for(itr=a1.begin();itr!=a1.end();itr++)
>>> {
>>>  value=*itr;
>>>  ans+=count(a2.begin(),a2.end(),value);
>>> }
>>>
>>> printf("%d\n",ans);
>>> return 0;
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh wrote:
>>>

 OK here is my code
 #include
 #include
 #include
 using namespace std;
 int compareints (const void * a, const void * b)
 {
   return ( *(long*)a - *(long*)b );
 }


 int main()
 {
 int n,s[101],a,b,c,d,e,f;
 long p1[19],p2[19];
 int i,j,k;
 scanf("%d",&n);
 for(i=0;i>>> //sort(s,s+i);
  k=0;
 for(i=0;i>>> {
 for(j=0;j>>> {
 for(int l=0;l>>> {
 if(s[l])
 p1[k++]=(s[i]+s[j])*s[l];
 }
 }
 }
 //sort(p1,p1+k);
 int x=0;
 for(i=0;i>>> {
 for(j=0;j>>> {
 for(int l=0;l>>> {
 //if(s[l]!=0)
 p2[x++]=(s[i]*s[j])+s[l];
 }
 }
 }
 sort(p2,p2+x);
 long *pItem;
 long count=0;
 for(i=0;i>>> {
 pItem = (long*) bsearch (&p1[i], p2, x, sizeof (long),
 compareints);
 if(pItem){

 long *tmp=pItem;
 if(pItem==p2)while(*(tmp)==p1[i]&&tmp>>> count++;tmp++;}
 else
 if(pItem==(p2+(x-1))) {
 while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}}
 else{
 tmp++;
 while(*(tmp)==p1[i]&&tmp>>> count++;tmp++;}

 while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}
 }
  //count++;
 }
 }
 printf("%ld\n",count);

 //for(i=0;i>>> //for(i=0;i>>> return 0;
 }


 Why is it getting segmentation fault?

 --
 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@go

Re: [algogeeks] Please explain this problem

2011-06-12 Thread saurabh singh
I did used the library functions but I am getting sigsegv after 0.03 s.I
cant understand why?I am presuming sumthing wrong about the implemenatation
of bsearch?
I am assuming bsearch is returning a pointer to the first found element.
On Sun, Jun 12, 2011 at 12:41 PM, keyan karthi wrote:

> upper_bound and lower_bound does a binary search to get count of alike
> terms.. which u tend to sum of to get the ans..
> out of the two arrays, u need to sort one array.. this will be teh vector
> in which u do the binary search wit every element of un sorted array..
> this is the approach i used... :) hope this helps...
>
> the above functions defined in "algorithm"
>
>
> On Sun, Jun 12, 2011 at 12:34 PM, nicks wrote:
>
>> and here is my code I'm Getting TLE i tried to implement binary search
>> but failed bcoz how will i be able to trace the value from one vector into
>> another vector if there are any multiple occureneces of any value(i mean i
>> have count them).in this code i i have used count of algorithm which may
>> be expensive...suggest a better way plz...thnx in advance !!
>>
>>
>>
>> #include
>> #include
>> #include
>> #include
>> #include
>> using namespace std;
>> int main()
>> {
>> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
>> scanf("%d",&num);
>> vector val,a1,a2;
>> for(i=0;i> {
>> scanf("%d",&t);
>> val.push_back(t);
>> }
>> for(i=0;i> {
>> a=val[i];
>> for(j=0;j> {
>> b=val[j];
>> for(k=0;k> {
>> c=val[k];
>> t=a*b+c;
>> a1.push_back(t);
>> }
>> }
>> }
>> for(i=0;i> {
>> d=val[i];
>> for(j=0;j> {
>> e=val[j];
>> for(k=0;k> {
>> f=val[k];
>> t=(f+e)*d;
>> a2.push_back(t);
>> }
>> }
>> }
>>
>> vector::iterator itr;
>> for(itr=a1.begin();itr!=a1.end();itr++)
>> {
>>  value=*itr;
>>  ans+=count(a2.begin(),a2.end(),value);
>> }
>>
>> printf("%d\n",ans);
>> return 0;
>> }
>>
>>
>>
>>
>>
>>
>> On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh wrote:
>>
>>>
>>> OK here is my code
>>> #include
>>> #include
>>> #include
>>> using namespace std;
>>> int compareints (const void * a, const void * b)
>>> {
>>>   return ( *(long*)a - *(long*)b );
>>> }
>>>
>>>
>>> int main()
>>> {
>>> int n,s[101],a,b,c,d,e,f;
>>> long p1[19],p2[19];
>>> int i,j,k;
>>> scanf("%d",&n);
>>> for(i=0;i>> //sort(s,s+i);
>>>  k=0;
>>> for(i=0;i>> {
>>> for(j=0;j>> {
>>> for(int l=0;l>> {
>>> if(s[l])
>>> p1[k++]=(s[i]+s[j])*s[l];
>>> }
>>> }
>>> }
>>> //sort(p1,p1+k);
>>> int x=0;
>>> for(i=0;i>> {
>>> for(j=0;j>> {
>>> for(int l=0;l>> {
>>> //if(s[l]!=0)
>>> p2[x++]=(s[i]*s[j])+s[l];
>>> }
>>> }
>>> }
>>> sort(p2,p2+x);
>>> long *pItem;
>>> long count=0;
>>> for(i=0;i>> {
>>> pItem = (long*) bsearch (&p1[i], p2, x, sizeof (long),
>>> compareints);
>>> if(pItem){
>>>
>>> long *tmp=pItem;
>>> if(pItem==p2)while(*(tmp)==p1[i]&&tmp>> count++;tmp++;}
>>> else
>>> if(pItem==(p2+(x-1))) {
>>> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}}
>>> else{
>>> tmp++;
>>> while(*(tmp)==p1[i]&&tmp>> count++;tmp++;}
>>>
>>> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}
>>> }
>>>  //count++;
>>> }
>>> }
>>> printf("%ld\n",count);
>>>
>>> //for(i=0;i>> //for(i=0;i>> return 0;
>>> }
>>>
>>>
>>> Why is it getting segmentation fault?
>>>
>>> --
>>> 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 Gee

Re: [algogeeks] Please explain this problem

2011-06-12 Thread keyan karthi
upper_bound and lower_bound does a binary search to get count of alike
terms.. which u tend to sum of to get the ans..
out of the two arrays, u need to sort one array.. this will be teh vector in
which u do the binary search wit every element of un sorted array..
this is the approach i used... :) hope this helps...

the above functions defined in "algorithm"

On Sun, Jun 12, 2011 at 12:34 PM, nicks  wrote:

> and here is my code I'm Getting TLE i tried to implement binary search
> but failed bcoz how will i be able to trace the value from one vector into
> another vector if there are any multiple occureneces of any value(i mean i
> have count them).in this code i i have used count of algorithm which may
> be expensive...suggest a better way plz...thnx in advance !!
>
>
>
> #include
> #include
> #include
> #include
> #include
> using namespace std;
> int main()
> {
> int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
> scanf("%d",&num);
> vector val,a1,a2;
> for(i=0;i {
> scanf("%d",&t);
> val.push_back(t);
> }
> for(i=0;i {
> a=val[i];
> for(j=0;j {
> b=val[j];
> for(k=0;k {
> c=val[k];
> t=a*b+c;
> a1.push_back(t);
> }
> }
> }
> for(i=0;i {
> d=val[i];
> for(j=0;j {
> e=val[j];
> for(k=0;k {
> f=val[k];
> t=(f+e)*d;
> a2.push_back(t);
> }
> }
> }
>
> vector::iterator itr;
> for(itr=a1.begin();itr!=a1.end();itr++)
> {
>  value=*itr;
>  ans+=count(a2.begin(),a2.end(),value);
> }
>
> printf("%d\n",ans);
> return 0;
> }
>
>
>
>
>
>
> On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh wrote:
>
>>
>> OK here is my code
>> #include
>> #include
>> #include
>> using namespace std;
>> int compareints (const void * a, const void * b)
>> {
>>   return ( *(long*)a - *(long*)b );
>> }
>>
>>
>> int main()
>> {
>> int n,s[101],a,b,c,d,e,f;
>> long p1[19],p2[19];
>> int i,j,k;
>> scanf("%d",&n);
>> for(i=0;i> //sort(s,s+i);
>>  k=0;
>> for(i=0;i> {
>> for(j=0;j> {
>> for(int l=0;l> {
>> if(s[l])
>> p1[k++]=(s[i]+s[j])*s[l];
>> }
>> }
>> }
>> //sort(p1,p1+k);
>> int x=0;
>> for(i=0;i> {
>> for(j=0;j> {
>> for(int l=0;l> {
>> //if(s[l]!=0)
>> p2[x++]=(s[i]*s[j])+s[l];
>> }
>> }
>> }
>> sort(p2,p2+x);
>> long *pItem;
>> long count=0;
>> for(i=0;i> {
>> pItem = (long*) bsearch (&p1[i], p2, x, sizeof (long),
>> compareints);
>> if(pItem){
>>
>> long *tmp=pItem;
>> if(pItem==p2)while(*(tmp)==p1[i]&&tmp> count++;tmp++;}
>> else
>> if(pItem==(p2+(x-1))) {
>> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}}
>> else{
>> tmp++;
>> while(*(tmp)==p1[i]&&tmp> count++;tmp++;}
>>
>> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}
>> }
>>  //count++;
>> }
>> }
>> printf("%ld\n",count);
>>
>> //for(i=0;i> //for(i=0;i> return 0;
>> }
>>
>>
>> Why is it getting segmentation fault?
>>
>> --
>> 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.



Re: [algogeeks] Please explain this problem

2011-06-12 Thread nicks
and here is my code I'm Getting TLE i tried to implement binary search
but failed bcoz how will i be able to trace the value from one vector into
another vector if there are any multiple occureneces of any value(i mean i
have count them).in this code i i have used count of algorithm which may
be expensive...suggest a better way plz...thnx in advance !!



#include
#include
#include
#include
#include
using namespace std;
int main()
{
int num,ans=0,value,i,j,k,t,a,b,c,d,e,f;
scanf("%d",&num);
vector val,a1,a2;
for(i=0;i::iterator itr;
for(itr=a1.begin();itr!=a1.end();itr++)
{
 value=*itr;
 ans+=count(a2.begin(),a2.end(),value);
}

printf("%d\n",ans);
return 0;
}






On Sat, Jun 11, 2011 at 11:57 PM, saurabh singh  wrote:

>
> OK here is my code
> #include
> #include
> #include
> using namespace std;
> int compareints (const void * a, const void * b)
> {
>   return ( *(long*)a - *(long*)b );
> }
>
>
> int main()
> {
> int n,s[101],a,b,c,d,e,f;
> long p1[19],p2[19];
> int i,j,k;
> scanf("%d",&n);
> for(i=0;i //sort(s,s+i);
>  k=0;
> for(i=0;i {
> for(j=0;j {
> for(int l=0;l {
> if(s[l])
> p1[k++]=(s[i]+s[j])*s[l];
> }
> }
> }
> //sort(p1,p1+k);
> int x=0;
> for(i=0;i {
> for(j=0;j {
> for(int l=0;l {
> //if(s[l]!=0)
> p2[x++]=(s[i]*s[j])+s[l];
> }
> }
> }
> sort(p2,p2+x);
> long *pItem;
> long count=0;
> for(i=0;i {
> pItem = (long*) bsearch (&p1[i], p2, x, sizeof (long),
> compareints);
> if(pItem){
>
> long *tmp=pItem;
> if(pItem==p2)while(*(tmp)==p1[i]&&tmp count++;tmp++;}
> else
> if(pItem==(p2+(x-1))) {
> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}}
> else{
> tmp++;
> while(*(tmp)==p1[i]&&tmp count++;tmp++;}
>
> while(pItem>=p2&&*(pItem)==p1[i]){count++;pItem--;}
> }
>  //count++;
> }
> }
> printf("%ld\n",count);
>
> //for(i=0;i //for(i=0;i return 0;
> }
>
>
> Why is it getting segmentation fault?
>
> --
> 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] Please explain this problem

2011-06-11 Thread saurabh singh
OK here is my code
#include
#include
#include
using namespace std;
int compareints (const void * a, const void * b)
{
  return ( *(long*)a - *(long*)b );
}


int main()
{
int n,s[101],a,b,c,d,e,f;
long p1[19],p2[19];
int i,j,k;
scanf("%d",&n);
for(i=0;i=p2&&*(pItem)==p1[i]){count++;pItem--;}}
else{
tmp++;
while(*(tmp)==p1[i]&&tmp=p2&&*(pItem)==p1[i]){count++;pItem--;}
}
 //count++;
}
}
printf("%ld\n",count);

//for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Please explain this problem

2011-06-11 Thread Terence

a,b,c,d,e,f do not need to be distinct.
(It is possible that a=b=c=d=e=f, see Example 1)

On 2011-6-10 12:01, saurabh singh wrote:

Problem link- ABCDEF 

Can someone please explain this problem.The problem says a,b,c,d,e,f 
belongs to S.But what if size of S is smaller than 6?

I know i am missing sumthing very trivialhelp plz.
--
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD


--
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] Please explain this problem

2011-06-11 Thread {{Udit Gupta}}
@aditya: can u b more precise??

On Fri, Jun 10, 2011 at 9:14 PM, ADITYA KUMAR  wrote:

> just visit spoj forums
>
>
> On Fri, Jun 10, 2011 at 9:42 AM, keyan karthi 
> wrote:
>
>> the nos can repeat :) ie the valid set may contain  multiple instance  of
>> a same number..
>> hope this helps :)
>>
>>
>> On Fri, Jun 10, 2011 at 9:31 AM, saurabh singh wrote:
>>
>>> Problem link- ABCDEF 
>>>
>>> Can someone please explain this problem.The problem says a,b,c,d,e,f
>>> belongs to S.But what if size of S is smaller than 6?
>>> I know i am missing sumthing very trivialhelp plz.
>>> --
>>> Saurabh Singh
>>> B.Tech (Computer Science)
>>> MNNIT ALLAHABAD
>>>
>>>
>>>  --
>>> 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.
>>
>
>
>
> --
> Regards
> Aditya Kumar
> B-tech 3rd year
> Computer Science & Engg.
> MNNIT, Allahabad.
>
>  --
> 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] Please explain this problem

2011-06-10 Thread ADITYA KUMAR
just visit spoj forums

On Fri, Jun 10, 2011 at 9:42 AM, keyan karthi wrote:

> the nos can repeat :) ie the valid set may contain  multiple instance  of a
> same number..
> hope this helps :)
>
>
> On Fri, Jun 10, 2011 at 9:31 AM, saurabh singh wrote:
>
>> Problem link- ABCDEF 
>>
>> Can someone please explain this problem.The problem says a,b,c,d,e,f
>> belongs to S.But what if size of S is smaller than 6?
>> I know i am missing sumthing very trivialhelp plz.
>> --
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT ALLAHABAD
>>
>>
>>  --
>> 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.
>



-- 
Regards
Aditya Kumar
B-tech 3rd year
Computer Science & Engg.
MNNIT, Allahabad.

-- 
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] Please explain this problem

2011-06-09 Thread keyan karthi
the nos can repeat :) ie the valid set may contain  multiple instance  of a
same number..
hope this helps :)

On Fri, Jun 10, 2011 at 9:31 AM, saurabh singh  wrote:

> Problem link- ABCDEF 
>
> Can someone please explain this problem.The problem says a,b,c,d,e,f
> belongs to S.But what if size of S is smaller than 6?
> I know i am missing sumthing very trivialhelp plz.
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT ALLAHABAD
>
>
>  --
> 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] Please explain this problem

2011-06-09 Thread saurabh singh
Problem link- ABCDEF 

Can someone please explain this problem.The problem says a,b,c,d,e,f belongs
to S.But what if size of S is smaller than 6?
I know i am missing sumthing very trivialhelp plz.
-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

-- 
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] please explain the output

2011-04-09 Thread ArPiT BhAtNaGaR
thx pratik

On Sat, Apr 9, 2011 at 8:13 PM, Pratik Kathalkar
wrote:

> u can see the pre-processed file using gcc -E prog_name.cand @
> bottom u can see what actually the code is doing.
>
>
> On Tue, Apr 5, 2011 at 12:45 PM, Arvind  wrote:
>
>> #include
>>
>> #define f(a,b) a##b
>> #define g(a) #a
>> #define h(a) g(a)
>>
>> int main()
>> {
>> printf("%s",g(f(1,2)));
>> printf("\t%s",h(f(1,2)));
>> return 0;
>> }
>>
>>
>>
>> i have run this program in gcc compiler and getting : f(1,2) 12 as
>> output.
>> can anyone explain the reason for getting this output?
>>
>> --
>> 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.
>>
>>
>
>
> --
> Pratik Kathalkar
> CoEP
> BTech IT
> 8149198343
>
>
>  --
> 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.
>



-- 
Arpit Bhatnagar
(MNIT JAIPUR)

-- 
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] please explain the output

2011-04-09 Thread Pratik Kathalkar
u can see the pre-processed file using gcc -E prog_name.cand @
bottom u can see what actually the code is doing.

On Tue, Apr 5, 2011 at 12:45 PM, Arvind  wrote:

> #include
>
> #define f(a,b) a##b
> #define g(a) #a
> #define h(a) g(a)
>
> int main()
> {
> printf("%s",g(f(1,2)));
> printf("\t%s",h(f(1,2)));
> return 0;
> }
>
>
>
> i have run this program in gcc compiler and getting : f(1,2) 12 as
> output.
> can anyone explain the reason for getting this output?
>
> --
> 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.
>
>


-- 
Pratik Kathalkar
CoEP
BTech IT
8149198343

-- 
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] please explain the output

2011-04-09 Thread Prakash D IT @ CEG
nice explanation

-- 
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] please explain the output

2011-04-09 Thread ArPiT BhAtNaGaR
COOL BRO THIS IS A GOOD SOLN

On Tue, Apr 5, 2011 at 4:10 PM, Azhar Hussain  wrote:

> Few Important things about macros, before I explain the output
> 1. Macros are replaced in passes.
>  2. Macros are not recursive.
>
> regarding the output remember the rule for expansion
> "A parameter in the replacement list, *UNLESS* preceded by a # or ##
> preprocessing token or followed by a ## preprocessing token, is replaced by
> the  corresponding argument after all macros contained therein have been
> expanded".
> In other words, macros are replaced "inside out" unless # or ## exists
>
> printf("%s",g(f(1,2)));  is replaced as #f(1,2) ---> "f(1,2)" according to
> the replacement rule.
> printf("\t%s",h(f(1,2)));  As this does not replace with # or ## directly,
> "inside out" expansion leads to h("1,2") --> g('1,2") --> "1,2"
>
> for the first pass
> printf("%s", "f(1,2)");  ---> g(a) #a
> printf("\t%s", h("1,2"));
>
> second pass
> printf("%s", "f(1,2)");  >> not processed(exhausted)
> printf("\t%s", g("1,2")); --> h(a) g(a)
>
> Third pass
>  printf("%s", "f(1,2)");  >> not processed(exhausted)
> printf("\t%s", "1,2");  --> g(a) #a
>
>
> Hope this answers your question.
>
> -
> Azhar.
>
>
>
>
> On Tue, Apr 5, 2011 at 3:22 PM, Vandana Bachani wrote:
>
>> Hi Arvind,
>> These are preprocessor specific operators. Check out
>> http://msdn.microsoft.com/en-us/library/wy090hkc(v=vs.80).aspx
>>
>> -Vandana
>>
>> On Tue, Apr 5, 2011 at 12:45 PM, Arvind  wrote:
>>
>>> #include
>>>
>>> #define f(a,b) a##b
>>> #define g(a) #a
>>> #define h(a) g(a)
>>>
>>> int main()
>>> {
>>> printf("%s",g(f(1,2)));
>>> printf("\t%s",h(f(1,2)));
>>> return 0;
>>> }
>>>
>>>
>>>
>>> i have run this program in gcc compiler and getting : f(1,2) 12 as
>>> output.
>>> can anyone explain the reason for getting this output?
>>>
>>> --
>>> 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.
>



-- 
Arpit Bhatnagar
(MNIT JAIPUR)

-- 
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] please explain the output

2011-04-05 Thread Azhar Hussain
Few Important things about macros, before I explain the output
1. Macros are replaced in passes.
 2. Macros are not recursive.

regarding the output remember the rule for expansion
"A parameter in the replacement list, *UNLESS* preceded by a # or ##
preprocessing token or followed by a ## preprocessing token, is replaced by
the  corresponding argument after all macros contained therein have been
expanded".
In other words, macros are replaced "inside out" unless # or ## exists

printf("%s",g(f(1,2)));  is replaced as #f(1,2) ---> "f(1,2)" according to
the replacement rule.
printf("\t%s",h(f(1,2)));  As this does not replace with # or ## directly,
"inside out" expansion leads to h("1,2") --> g('1,2") --> "1,2"

for the first pass
printf("%s", "f(1,2)");  ---> g(a) #a
printf("\t%s", h("1,2"));

second pass
printf("%s", "f(1,2)");  >> not processed(exhausted)
printf("\t%s", g("1,2")); --> h(a) g(a)

Third pass
printf("%s", "f(1,2)");  >> not processed(exhausted)
printf("\t%s", "1,2");  --> g(a) #a


Hope this answers your question.

-
Azhar.




On Tue, Apr 5, 2011 at 3:22 PM, Vandana Bachani wrote:

> Hi Arvind,
> These are preprocessor specific operators. Check out
> http://msdn.microsoft.com/en-us/library/wy090hkc(v=vs.80).aspx
>
> -Vandana
>
> On Tue, Apr 5, 2011 at 12:45 PM, Arvind  wrote:
>
>> #include
>>
>> #define f(a,b) a##b
>> #define g(a) #a
>> #define h(a) g(a)
>>
>> int main()
>> {
>> printf("%s",g(f(1,2)));
>> printf("\t%s",h(f(1,2)));
>> return 0;
>> }
>>
>>
>>
>> i have run this program in gcc compiler and getting : f(1,2) 12 as
>> output.
>> can anyone explain the reason for getting this output?
>>
>> --
>> 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.



Re: [algogeeks] please explain the output

2011-04-05 Thread Vandana Bachani
Hi Arvind,
These are preprocessor specific operators. Check out
http://msdn.microsoft.com/en-us/library/wy090hkc(v=vs.80).aspx

-Vandana

On Tue, Apr 5, 2011 at 12:45 PM, Arvind  wrote:

> #include
>
> #define f(a,b) a##b
> #define g(a) #a
> #define h(a) g(a)
>
> int main()
> {
> printf("%s",g(f(1,2)));
> printf("\t%s",h(f(1,2)));
> return 0;
> }
>
>
>
> i have run this program in gcc compiler and getting : f(1,2) 12 as
> output.
> can anyone explain the reason for getting this output?
>
> --
> 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] please explain the output

2011-04-05 Thread Arvind
#include

#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)

int main()
{
printf("%s",g(f(1,2)));
printf("\t%s",h(f(1,2)));
return 0;
}



i have run this program in gcc compiler and getting : f(1,2) 12 as
output.
can anyone explain the reason for getting this output?

-- 
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] Please Explain

2011-01-04 Thread Devil Wang
*you can just change the code as followed:*
*
*
*int *b = ( int * ) malloc(sizoeof(int) * b[2]);*
*or *
*int *b = new int[b[2]];
*
On Tue, Jan 4, 2011 at 5:58 AM, Aniket  wrote:

> #include
> using namespace std;
> const int a[]={1,2,3,4,5};
> int b[a[2]];
> int main(){return 0;}
>
> If the code is like above it is giving error in line 4;
>
> But if it is something like below it gives no error after compilation:
>
> #include
> using namespace std;
> const int a=3;
> int b[a];
> int main(){return 0;}
>
> Anybody please expalin.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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.
>
>


-- 

**
*

Best Regards,

Devil Wang

*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] Please Explain

2011-01-03 Thread Aniket
#include
using namespace std;
const int a[]={1,2,3,4,5};
int b[a[2]];
int main(){return 0;}

If the code is like above it is giving error in line 4;

But if it is something like below it gives no error after compilation:

#include
using namespace std;
const int a=3;
int b[a];
int main(){return 0;}

Anybody please expalin.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] please explain the output

2010-11-05 Thread Piyush
*The prototype of printf is*
*int printf(const char ***format**, ...);*
*
*
*Thus it takes a string and then variable number of arguments.*
*
*
*Every argument passed after (char *format)string is to resolve the"%"
inside the string (which is passed as the first argument)*
*
*
*Thus "anuj" will be printed as normal as printf("anuj");*
*Since "anuj" which is char *format for the printf function does not need to
resolve % because there aren't any.*
*
*
It will be good to read the printf implementation in  Dennis Ritchie to get
a better understanding

On Fri, Nov 5, 2010 at 7:58 PM, ANUJ KUMAR  wrote:

> #include
> int main()
> {
>printf("anuj","kumar");
>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 algoge...@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 algoge...@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] please explain the output

2010-11-05 Thread ANUJ KUMAR
#include
int main()
{
printf("anuj","kumar");
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 algoge...@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] please explain the pointer math on page 22 of this pdf

2010-09-29 Thread rahul rai
Ya , i get it now . ReThanks!

2010/9/29, Sathaiah Dontula :
> int arr [100]; /* array to search */
> *
> Let's write a simple search function:
>
> int *linear _search ( int val) {
> int *parr, *parrend = arr + array _length(arr);
>
> for (parr = arr; parr < parrend; parr++) {
>   if (* parr == val )
>   return parr ;
>  }
>
> return NULL;
> }
>
> Talking about this problem, parrend is pointing to the end of arr, it is
> like arr + 100 same as arr + sizeof(arr)/sizeof(int);
> Now loop starts from the array start and then goes till the end and when the
> values matches with the val then loop breaks.
>
> Some code in without pointers,
>
> int arr[100];
> int *linear _search ( int val) {
> int index_start, size;
>
> size = sizeof(arr)/sizeof(int); //100
>
> for (index = 0; index < size; index++) {
>   if (parr[index] == val )
>   return &parr[index] ;
>  }
>
> return NULL;
> }
>
> please let me know if you have any comments.
>
> Thanks,
> Sathaiah
>
> On Tue, Sep 28, 2010 at 11:34 PM, rahul rai  wrote:
>
>>
>> http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/MIT6_087IAP10_lec05.pdf
>>
>> Thanking In Advance
>> --
>> Rahul K Rai
>> "And The Geek Shall Inherit The Earth"
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@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 algoge...@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.
>
>


-- 
Rahul K Rai
rahulpossi...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] please explain the pointer math on page 22 of this pdf

2010-09-29 Thread Sathaiah Dontula
int arr [100]; /* array to search */
*
Let's write a simple search function:

int *linear _search ( int val) {
int *parr, *parrend = arr + array _length(arr);

for (parr = arr; parr < parrend; parr++) {
  if (* parr == val )
  return parr ;
 }

return NULL;
}

Talking about this problem, parrend is pointing to the end of arr, it is
like arr + 100 same as arr + sizeof(arr)/sizeof(int);
Now loop starts from the array start and then goes till the end and when the
values matches with the val then loop breaks.

Some code in without pointers,

int arr[100];
int *linear _search ( int val) {
int index_start, size;

size = sizeof(arr)/sizeof(int); //100

for (index = 0; index < size; index++) {
  if (parr[index] == val )
  return &parr[index] ;
 }

return NULL;
}

please let me know if you have any comments.

Thanks,
Sathaiah

On Tue, Sep 28, 2010 at 11:34 PM, rahul rai  wrote:

>
> http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/MIT6_087IAP10_lec05.pdf
>
> Thanking In Advance
> --
> Rahul K Rai
> "And The Geek Shall Inherit The Earth"
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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 algoge...@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] please explain the pointer math on page 22 of this pdf

2010-09-28 Thread rahul rai
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/MIT6_087IAP10_lec05.pdf

Thanking In Advance
-- 
Rahul K Rai
"And The Geek Shall Inherit The Earth"

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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.