Tuesday, December 15, 2009

Some more problems of SPOJ...

I recently breached into the top 1200 ranks in the world, but sad news is, soon I'll be thrown out too. The points keep on decreasing on a regular basis. Never mind this works as an incentive to work on more and more problems. :)
So, m writing this post for some more problems of SPOJ. The problems I m going to discuss are of an average level.

BISHOPS: Its an easy problem, if we try verbally. The answer is (2*n-2) i.e. equal to the number of diagonals. But the difficulty lies in the range of the inputs. N<=10^100..!! OMG!!.. :).. Try strings..

MINCOUNT: Actually what I did.. I tried it out for certain test cases and found that the answer is.. (n*(n+1)/2)/3.. i.e. the total number of coins in the triangle divided by 3. But why its so.. its still unanswered for me.. kindly post the explanation if you get one..!! :)

HUBULLU: Same mincount type problem here too.. seeing the discussion in the forum I got some hints that who so ever plays first wins.. So, it became a very very easy question for me to crack but why it happens is yet not understood by me..

TRICOUNT: Its another mathematics problem.. try it for sometime with all yours geometrical anlysis and at one time you will definitely come out with a solution that is much like (t*(t+2)*(2*t+1))/8.. where t is the level of triangle. Try it now yourself..!!

SAMER08F: Another age old problem of how many squares are there in a given bunch of squares?? Answer lies in the sum all squared numbers till the number of squares in each side of the grid i.e. if N=8 then answer= (1*1) + (2*2) + ... + (8*8).

Seeing my last three posts of SPOJ I think now its easy for any newbie to get started. So, no more discussing algorithms of SPOJ problems from my side. Keep practicing and who knows one day you beat [Trichromatic] XilinX..!! :p

* * * * *

Saturday, November 21, 2009

SPOJ: Some very easy problems

Its been a month since I have started coding in SPOJ. There are over 5000 problems present there. Its really gets very tough when one tries to get some easy problems from that lot. So, I dedicate this post to beginners. Go for the below mentioned problems.

Some very easy classical problems:

TEST- This is the first problem I solved in SPOJ. I recommend the same for you. It gives a brief introduction of the whole environment. What you need to do is to accept and print the input by the user until you come across 42. The easiest problem at SPOJ and a confidence booster to begin with..!! ;)

ADDREV- Take two numbers as input. Reverse both. Add the reversed number. Reverse again. Simple..!! The thing you need to keep in mind is that you have to provide the number of test cases first. While taking the inputs you can print the result too. You need not store them and print later.

FASHION- Quite big explanation of the problem (a bit interesting too ;) ). The only thing you need to keep in mind is that you have to sort the degree of hotness of men and women and then multiply and add them up. If you do not sort them, it will give a WA.

MIRRORED- Print "Mirrored pair" wherever you confront "bd" or "db" or "pq" or "qp", otherwise print "Ordinary pair". Don't forget to print "Ready" in the beginning. You do not have to take the test cases as input here. Just end the input when you confront two spaces. I got an AC at very first attempt..!! Hope the same for you.. :)

NSTEPS- Analize the graph properly. Whenever x and y co-ordinates are even the corresponding output is (x+y) for input (x=y) and (x=y-2). When they are odd the corresponding ouput is (x+y-1) for input (x=y) and (y=x-2). You can also do the problem with a different approach too. You can form a series for the numbers, and hence, generate the output.

OFORTUNE- Common.. don't get astonished by the enormous length of the question. Try tackling the problem. It just needs six inputs and a simple interest and compound interest formula implementation thats it.. Try it.. You will gain a hell lot of points..!!

Some very easy challenge problems:

SIZECON- The difficulty doesn't lie in the problem statement. The difficulty lies in the choice of programming language. I managed to do it in 96 characters. Best solution in c++ has 70 characters in it. Perl language wins with just 6 characters..!!

BFWRITE- I have already written a post about this problem. Try learning Brainf_ck language and solve this problem too. Here's the link to my post.

More easy problems are being searched. Kindly mention some in comments if you confront one.. Here's my SPOJ handle.. vaibhav_pandey.

* * * * *

Saturday, November 14, 2009

Getting started with Project Euler



Hello folks.. After getting started with SPOJ and TOPCODER, lets get started with another fine programming competition which is Project Euler.

The first question which originates is.. why Project Euler??

My answer.. why not?? If you are interested in programming.. make yourselves interested in mathematical shortcuts and logics for solving problems too. Project Euler is a site that provides you problems that bind you to explore some unexplored areas of mathematics. Now, lets get started..

Steps:
  • Get registered.
  • See the problems from problems tag. There are more than 260 problems at present.
  • Solving problems requires you either to build a source code that computes the asked value or to pick up pen and paper and start solving. My advice.. prefer the earlier one..!! :)
Your profile consists of the number of problems you have solved. Your ranking is based on levels. If you have successfully solved 25 questions you qualify to the level 1 and so on and so forth. On solving a problem its thread gets unlocked and you can check solutions of others in the languages they preferred. Thus, you can compare your code with others.

Your profile gets dissolved if no activity happens in 90 days of time. This happens if you are 0, 1 or 2 level programmer. Level 3 and level 4 programmers are granted immortality, thus, here lies the advantage of being superior.. 8)
So, get started with Project Euler and hone your programming skills..

To see my profile, first register to the site and then type the URL: http://projecteuler.net/index.php?section=profile&profile=vaibhav_pandey

* * * * *

Thursday, November 5, 2009

My experience with BrainF_ck Programming Language

Hi folks.. Last few days I worked a bit on BrainF_ck language. A nice language that may be used for encoding sort of stuff. What we code in it.. it might happen that we ourselves forget about it, such is the level of complexity of the language!!
The brilliant factor about the language is that it is just made of eight symbols in total..!! Surprised.. so was I..!! :D

Whole of the language depends on just an array. Every manipulation has to be done in the array using a memory pointer, which moves through the memory blocks of the array. Now, getting over to the practical implementation of the language. The eight symbols are:

> = increases memory pointer, or moves the pointer to the right 1 block.
< = decreases memory pointer, or moves the pointer to the left 1 block.
+ = increases value stored at the block pointed to by the memory pointer
- = decreases value stored at the block pointed to by the memory pointer
[ = like c while(currentBlockValue != 0) loop.
] = if block currently pointed to's value is not zero, jump back to [
, = like c getchar(). input 1 character.
. = like c putchar(). print 1 character to the console.
I made my first program for SPOJ challenge problem BFWRITE. Before going through the code I would give you the link of an online compiler for BrainF_ck language. I prefer BrainF interpreter. So now, here's my code:
  1. ++++++++++
  2. [
  3. >+++++++>++++++++++>+++<<<-
  4. ]
  5. >+++++++++++++.
  6. ---.
  7. -.
  8. -----.
  9. >>++.
  10. <+++++.
  11. ++++++++++.
  12. >.
  13. <----------.
  14. +++++.
  15. ----------.
  16. +.
  17. .
  18. -.
  19. >.
  20. <---.
  21. ++++++++++++++++++++++.
  22. ------------------.
  23. ++++++++++++++.
  24. ----.
  25. --.
  26. --------.

Looks quite difficult to understand but I'll make it simpler for you.
  • First line assigns value 10 to a[0]
  • Second line begins a loop checking value of current block a[0].
  • Third line moves pointer ahead once(>) and assigns value 7 to a[1](++++++). The same line then again pushes pointer to a[2] and assigns value 10. 3 value is given to a[3]. The pointer returns back to a[0](<<<) and decrements the value to 9.
  • In the fourth line.. loop goes on until the value of a[0] exhausts.
  • Finally the values are.. a[0]=0, a[1]=70, a[2]=100, a[3]=30.
  • The sixth line decreases a[1] by 3 and makes its value equal to 67. '.' prints the value 'S', ASCII code of 67.
  • Likewise the further lines print the text:- 'P','O','J',' ','i','s',' ','i','n','d','e','e','d',' ','a','w','e','s','o','m','e'. Hence on our output comes as:- SPOJ is indeed awesome.
I further improved my code to 153 characters. Instead of making the array 70, 100, 30 in the beginning I made the array as 64, 32, 104, 112. Try it out yourself to optimize the code.

* * * * *

Friday, October 30, 2009

How to handle very large test cases in c++

Most of us come across some c++ problems where we are asked to get some simple calculations done. For example: we can get a problem of subtracting 1 from a 100 digit number. Now, subtracting one is not a big problem for us but the problem is '100 digit number'.

None of the datatype has capacity to store such a large number. Stop thinking about unsigned long long.. even it cant..!! So, here's a short solution to this cute problemo..

We can take the input as a string and process each of its elements as in elementary mathematics i.e. if last digit is'nt 0 then reduce it by 1(dont forget it to convert to int and then back to string).. if last digit is zero then make it nine and move back to the adjacent digit following the same procedure. Simple :)

Here's the source code..

#include
using namespace std;
int main()
{
int i,t=40;
string z;
cin>>z;
i=z.size()-1;
do
{
if(z[i]!='0')
{
z[i]=int(z[i])-1;
break;
}
z[i--]=57;

}while(i>=0);
Then print the string a.

The only problem comes when we give input as 10, 100, 1000, 10000 ... the answer comes out as 09, 099, 0999, 09999... instead of normal numbers such as.. 9, 99, 999, 9999... I have resolved this problem for myself.. I'll not upload the source.. try it out yourself..!! ;)

* * * * *

Sunday, October 18, 2009

Getting started with TopCoder..



After successfully coding the first time in Topcoder, I really feel greatful in sharing my experience with all. Simply, it was great. Got to learn a lot of new things. I have started it too late but being in UPTU and that too in a college where seniors are not that into coding, it was still very early.. ;)

So, m writing this post to acquaint my mates with the TopCoder Competitions. What I m goin to discuss is all about the algorithm competitions.
Top Coder is a programming arena where you are given a set of problems and you have to solve them (in your preferred language) in a given amount of time. There are some simple steps to follow before starting with the coding competition:
  • Goto Topcoder site and get yourself registered.
  • Now when you are registered, download the Topcoder arena. You will need Java to be installed in your system for making the applet run.
  • Get yourself an editor(I use KawigiEdit). The editor helps in generating the code required for the competition. If you need help to install it.. read this.
  • Start the contest application and start navigating. There are practice rooms where you can practice the earlier SRM's(single round matches).

SRM are the single round matches which are organized twice every month. You are given three problems to solve. What you need to do is to generate the code using KawigiEdit and simply put your logic in the function provided.
The important point about TopCoder is that you don't use the main() method in your code. All your logic is dumped inside a function and you have to return your answer instead of printing it.
The several phases of the competition are:
  • Coding Phase: During this phase you are given 75mins of time to solve as many problems as you can. What you need to do is to write your code, compile it and after rigourous testing on test cases provided and some of your own test cases, "submit" it.
  • Intermission: 5mins intermission.. I hear a song usually.. :)
  • Challenge Phase: During this phase in 20mins time any of the room members can see your code or you can see theirs. If anyone finds anything wrong with anyone's code, he can simply challenge it. If he succeeds the submitted problem will be discarded and points will fall back to 0.00
  • System Testing Phase: After the challenge phase comes System Testing Phase. This takes a fare bit of time. After near about 20mins you can goto tools and room summary for checking whether your code passed the System Testing or not.
After about 2 hrs of play the result is out..!! If you see your name coloured (Green,Blue,Yellow,Red), feel like a champ. If you are Grey, you need to practice more and more. The colors listed above are in hierarchical order.. i mean Red is the highest pointer(2200+) whereas grey is the lowest(001-899).

Being associated with IEEE, TopCoder is a good platform for being recruited. Moreover, it hons your programming skills, giving your career a boost.

You can watch your entire TopCoder profile by just entering your username in the handle.
I m listing some of the TopCoder handles that will inspire you a lot..
Some foreigners:
ACRUSH
petr

Some Indians:
konqueror
innocentboy
vijay03
shalinmangar (from JSS.. a thing to feel proud of..)

Here's my handle.. its not that good.. I'll improve it further.. m sure..
vaibhavpandey

* * * * *

Wednesday, October 14, 2009

SIGSEGV error in c++ programs

While solving a question TOANDFRO in spoj I was introduced to the SIGSEGV (segmentation fault) error. The very first thing, as I often do, I googled the error. The forums I visited and info I got simply did'nt tell me what exactly went wrong with my code. So, after a "deep-deep" analysis I m here to provide my readers with the solution to such an error.

There are various causes of segmentation faults, but fundamentally, you are accessing memory incorrectly. This could be caused by dereferencing a null pointer, or by trying to modify read only memory, or by using a pointer to somewhere that is not mapped into the memory space of your process.
A segfault basically means you did something bad with pointers. This is probably a segfault:

char *c = NULL;
...
*c; // dereferencing a NULL pointer

Or this:

char *c = "Hello";
...
c[10] = 'z'; // out of bounds, or in this case, writing into read-only memory

Or maybe this:

char *c = new char[10];
...
delete [] c;
...
c[2] = 'z'; // accessing freed memory

* * * * *

Saturday, October 3, 2009

Getting started with SPOJ (Sphere Online Judge)

After successfully getting involved in SPOJ I think I must give a little idea of it to others too. SPOJ is an online coding website for practicing ACM-ICPC style problems.
You need to join this website if you are interested in coding and have a thirst to solve new problems otherwise you can sit back and relax hearing your music stuff.. :p

To start with you can register for SPOJ here.
After getting registered you can see number of problems. Right now there are around 4K+ problems at SPOJ. For submitting a problem in whichever language you desire you can click submit and submit your file or directly the source code. One of the best things about online judges is their instant feedback. You dont have to wait for your program to get judged! The judge results are:
  • Accepted – The output from your program perfectly matched the required output. This problem is then added to your list of accepted problems.
  • Time Limit Exceeded – It means your program took too long to execute. Try optimizing your program and check for accidental infinite loops.
  • Wrong Answer – Your program ran on time, but it did not produce the required output.
  • Compile Error -Your program had some syntax error. For these errors, click on the text “Compile Error” in the judge result. It`ll take you a page which will list the compile errors and their line numbers in your program. The compilation error can also be sent to you as mail.
  • Runtime Error – This is usually accompanied by a code like SIGSEV. It can happen due to a lot of reasons, but the two most common are using too much memory ( you can use around 6000*6000*4 bytes of memory ) and not remembering to use int main() and return 0 in your programs. (NZEC error).
Your ranking in SPOJ arena is dynamic. More the number of users who solve the problem you'v solved lesser will be points gained. The points you gain in SPOJ come with the formula:

points= 80/(40+users successfully solved the problem)

So, more the difficult question you solve more points you get and higher is your rank. Even your institute gets ranked on your points. Check your institute's rank here.

Here is my SPOJ handle.. vaibhav_pandey

Start coding now!!!

* * * * *

Tuesday, September 29, 2009

SCALA programming language

While coding in SPOJ. I came across a new programming language named SCALA. I searched a hell lot of things about the language.

Scala goes out of it's way to make sure you don't need to program in a functional style. This is the main criticism of Scala from functional folks, as a matter of fact: some do not consider a language functional unless it forces the programmer to write in functional style.
Scala already introduces some nice features, comparable to some stuff that's present in C++ but not Java, though they work in different fashion. In that respect, once you realize what such features are for and relate them to C++ stuff, you'll be much ahead of Java programmers, as you'll already know what to do with them.

Some of the downsides of Scala are not related at all to the relative youth of the language. After all, Scala, has about 5 years of age, and Java was very different 5 years into its own lifespan.
In particular, because Scala does not have the backing of an enterprise which considers it a strategic priority, so the support resources for it are rather lacking. For example:

* Lack of extensive tutorials
* Inferior quality of the documentation
* Non-existing localization of documentation
* Native libraries (Scala uses Java or .Net libraries as base for their own)

* * * * *

Sunday, September 20, 2009

Optimization

During coding, what we need to keep in our minds is optimize the code. The direct code which hits our brain at the first instance is generally not that optimized. If given a large test case to examine the code, it fails to complete the execution in time. I came to know about this while playing online a coding event in which besides code to be right one's code should run in an asked period of time. For this we need to optimize our code a great extent.
I was asked to print all the prime numbers between given two numbers. The first code that comes to our mind is to run a loop and find all the prime numbers by dividing each number with every other number. Mind you, this takes a hell lot of time. One can optimize the code easily by discluding the numbers that get divided by 2,3,5. This takes away numbers out from the loop that prevent us from checking them. The time limit set hence becomes a little reachable.
The second thing is logic. One can even look at the problem at different angle. You can yourself Google and find that there are many other good methods of finding a prime number. One method needs the loop to run only for (n)^(1/2) times. This also reduces the time a great deal.

CODE IT.. OPTIMIZE IT!!

* * * * *

Friday, September 11, 2009

Back up your Gmail account



Gmail doesn't have to go down globally for our email access to be cut off—our internet could go down, or our account could even be disabled. Whatever the case, it's a good idea to have a backup plan just in case the worst should happen.

They've got us covered with a number of methods for backing up our Gmail, starting with the really obvious solution of just using Thunderbird to back up our email with POP access, but we can backup our email with Fetchmail on Windows, Getmail on Linux, the standalone Gmail Backup tool, or even use Google Groups to backup your Gmail account.

So, don't think much.. just get urself backed up!!

* * * * *

Thursday, September 3, 2009

Google Code Jam 2009

This was the first time I registered for Google Code Jam. Researching about this great event I came to know that it gives way to free use of languages. Google allows its participants to code in any language they wish to. Starting from c, c++, java, batch files to php, perl, brainf*ck and all.

It was the qualification round in which I scratched my 'hairless' head throughout the day. The round consisted of three questions. One had to submit an output file of solution of test cases. Each question consisted of two test cases small and large. 4 minutes of time was given to a participant to upload his source code file and the output file in small test cases. Time was increased to 8 mins in case of large test cases. It was necessary to solve at least one small test case and one large test case of any question to qualify for next round. I was able to solve a small one.. :)

The question I solved was called "Alien Language". One can easily 'google' the whole question. I m giving the source code which I submitted :

using namespace std;
int change(string strConvert)
{
int intReturn;
intReturn = atoi(strConvert.c_str());
return(intReturn);
}

void main()
{
ifstream myfile("g1.txt");
ofstream opens("g2.txt");
string line;
int cases=0;
char words[800][800],letters[800][800],answers[800][800];
int L,D,N,r=0,c=0,f=0,m;
getline(myfile,line,' ');
L=change(line);
getline(myfile,line,' ');
D=change(line);
getline(myfile,line,'\n');
N=change(line);
for(long int i=0;i++)
{
getline(myfile,line,'\n');
for(int j=0;j++)
{
words[i][j]=line[j];
}
words[i][L]='\0';
}
for(int q=0;q++)
{
cases=0;
r=0;
getline(myfile,line,'\n');
f=0;
m=line.size();
while(f!=m)
{
if(line[f]=='(')
{
while(line[f]!=')')
{
f++;
if(line[f]!=')')
{
letters[r][c]=line[f];
c++;
}
}
letters[r][c]=NULL;
f++;
r++;
c=0;
}
else
{
letters[r][c++]=line[f];
letters[r][c]=NULL;
r++;
c=0;
f++;
}
}
for(long int s=0;s++)
{
f=0;
for(long int k=0;k+)
{
for(long int a=0;a++)
{
if(words[s][k]==letters[k][a])
{
f++;
break;
}
}
}
if(f==L)
cases++;
}
opens<<"Case #"<<<": "<<<"\n";
}
getch();
}

Explanation of code:
What I did in the program is that I took each word of language into a double dimension array called 'words'. Each test case was then bifercated into letters in another double dimension array called 'letters'. The first letter in words was then regularly checked in the different letters of each test case. The moment it matched the loop got broken with an increment of a flag called 'f'. The moment flag became equal to length of word it was sure that the given combination exists, hence, the case variable gets incremented which is ultimately our answer and gets written in the output file.
The only problem that came with this solution was during the execution of large test case. It would have been easily implemented through vectors but lack of time compelled me to quit upon it. Actually, due to continuous memory allocation sometimes due to large datasets, the values get written on read only part of memory which generates errors.

So, I settled with a 10 point mark.. BTW my first experience with Google Code Jam was awesome..!!
* * * * *

Monday, August 31, 2009

Installing apache on windows

Instalation:

First thing you need is to download the webserver. Now for windows users you will have to go for the .exe . The apache website is www.apache.org. You have to head to the apache binaries sections for Win32. I believe it is at http://www.apache.org/dist/httpd/binaries/win32/
There you will be able to download a version of apache.

Now before you download it you have to make a folder. This folder is one which serves as the root directory. Now if you don't want to do this it's ok. You can use the default path if you want. But usually this helps in setting up other things like php, and MySQL. Most people create a folder in the C:\ directory called WWW or somthin. You can name it whatever you want.

Ok so you have downloaded the Apache Web Server and ready to go with the setup. The version I have downloaded was apache_2.0.36-win32-x86-no_ssl.msi. This was a newer version and supposedly supposed to be more secure.
  • The first screen you get when your in the setup is the welcome screen, we don't care much about that.
  • The next screen is the terms and service. And yes you are going to agree to the terms.
  • The next screen is some documentation. I never really read it but if you want go ahead and do it.
  • Now we see a screen that says enter a network domain. Erase what's in there and type localhost.
  • Now the next box says Servername, erace what is ever in the box and put in localhost.
  • The next is Administrators e-mail address. Go ahead and fill that in. But make sure to change it.
  • Pick radio button that best suites your needs.
  • Now that we got that all filled out. Hit Next and you'll go to a screen that asks you which type of install you want to do. Then hit next.
If you wanted to server out of your one special folder. Change the file location where you were going to install apache. Or just leave it as the default path. Click install and it should be on it's way. Once it's done installing hit the finish button.

The test:
First were gonna check to see if Apache installed correctly.
This is how we do it. Open up Internet Explorer and type in " http://localhost" . If everything went smooth then you should be seeing a message that looks like this" Seeing this instead of the website you expected?" Yippee!!!
Apache is working.

* * * * *

Thursday, August 13, 2009

DB2 Certification




A few days training and a stressfull test. All gave me an IBM DB2 associate certificate. What a relief at last!!I would like to share my experiences with the software. BTW m still learning a hell lot of things in it.
DB2 is a database handling software that helps in maintaining large databases. I learned its express-c edition which is available in market free of cost but the most eye catching was the everyplace edition that works on mobile phones. I did'nt get the chance to work on it but soon I will.The installation process though was simple yet hectic. Lots of errors.Command center, configuration assistant, task center, journals, health center, sql assist were all easy to understand. It was very much comfortable to build the sql statements on sql assist with a GUI interface. Express-c edition comes with a pure XML add-on feature. The XML datatype helps in including the XML files in a database. XML files have user defined tags which is where they differ from HTML files where the tags are pre-defined. XML files mainly find their use in transportation and storage of data.Working on sql queries was not new but that on xqueries was a new experience.
Three cheers for IBM for making us, the "UPTU's ruined geniuses", understand such a software. DB2 9.7 "VIPER2" is what I m looking ahead for.

* * * * *

Friday, August 7, 2009

The problem of fu#king "Back" button..

Sorry for my indecent title but I was so irritated by this "back" button that I cud'nt stop myself.
After a user logs out himself from a web page and presses the "back" button of his browser he again gets himself logged in. The problem really makes you scratch your head sometimes. I did the same and came out with a cool solution.

The page in which you are asking user to log out just write the two statements on page load():

Response.CacheControl = "no-cache";
Response.Cache.AppendCacheExtension("no-store");

The two statements help in controlling the cache and preventing it to save the previous session.

Also make a session variable for login of a user. Make the session variable "true" whenever a user logs in and "false" when he logs out. Check on page load() of logout page, if session variable holds "false" value, direct the page to login page. Now if the user clicks back button he'll still remain in the login page or the page you wish to direct him.
My codes:

protected void Page_Load(object sender, EventArgs e)
{
Response.CacheControl = "no-cache";
Response.Cache.AppendCacheExtension("no-store");
if (Session["log"] != "true")
{
Response.Redirect("expired.aspx");
}
}

* * * * *

Thursday, August 6, 2009

Cool query 'bout pointers

While studying 'bout pointers I came about a cool phenomenon. Plzz don't laugh if its a but obvious thing for you. You might be a better coder than me for sure. I figured it out after a number of trials so I can't stop myself sharing it with everyone.

My question is.. Whats the difference between two statements..
int a=1;
int *p;
*p=a;//statement 1

AND

int a=1;
int *p;
p=&a;//statement 2

I played with number of printf's to come out with a simple answer. I again warn you if its a but obvious thing plzz do ignore it but it was a beautiful discovery for me though.

p=&a : in this statement, as we all know, the address of variable 'a' gets stored in pointer p and we say that pointer p points towards the variable a.

*p=a : (value of p is equal to a) in this statement, "as now I know", a new address is designated as value 1 and the pointer points to that address rather than pointing towards a. In simple words the address stored in p is not the address of a.

try two statements with..
printf("%u" "%u",p,&a);
In first you will find same address and different in the second.

* * * * *