How Many Ip Address !!!

Given a string containing only digits, restore it by returning all possible valid IP address combinations.
For example:
Given “25525511135”,
return [“255.255.11.135”, “255.255.111.35”]{hint:recursion,backtrack}

Here is the Solution ……
it was taken me about 5 hours to solve see !!!

//cc Arun Kumar Gupta

import java.util.*;
public class AllIpAddress
{
public static void main (String [] args)
{
Scanner sc = new Scanner(System.in);
String input = sc.next();
int[] intArray = new int[input.length()];
int length = input.length();

for (int i = 0; i < input.length(); i++) {
intArray[i] = Character.digit(input.charAt(i), 10);
//System.out.println(intArray[i]);
}
int i = 0 , j = 1 , k = 2;
AllIpAddress ip = new AllIpAddress();
ip.Ipaddress(intArray , i , j , k , length-1);

}
void Ipaddress(int [] intArray , int i , int j , int k , int length)
{
try{
int where = 0 ,change = 0;
int p1 =createIP( intArray , -1 , i);
int p2 =createIP( intArray , i ,  j );
int p3 =createIP( intArray ,  j , k );
int p4 =createIP( intArray ,  k ,  length );
//System.out.println(“**********Garbage”+p1+”.”+p2+”.”+p3+”.”+p4);
//System.out.println(“i = “+i+”j = “+j+”k = “+k);
if((p1<=255)&&(p2<=255)&&(p3<=255)&&(p4<=255)&&(p4>0))
{
System.out.println(p1+”.”+p2+”.”+p3+”.”+p4);
}
if(p4 >255)
{
//if(k != j)
//++k;
where =4;
//System.out.println(“Problem at P4”);
}
else if(p3>255)
{
//if(j != i)
//++j;
//–k;
where = 3;
//System.out.println(“Problem at P3”);
}
else if(p2>255)
{
//++i;
where = 2;
//System.out.println(“Problem at P2”);
}
else if(p1>255)
{

//System.out.println(“Problem at P1”);
System.exit(0);
}

if((k == length) && (j+1 == k))
{
//System.out.println(“if((k == length) && (j+1 == k))”);
//System.out.println(i+”_”+j+”_”+k);
++i;
j = i+1;
k = j+1;
change = 1;
//System.out.println(i+”_”+j+”_”+k);

}
if((k == length) &&(change == 0) )
{
//System.out.println(“if((k == length) &&(change == 0) )”);
++j;
k = j+1;
change = 0;
}
else if(change == 0)
{
if( (k) < length )
++k;
}
/*if(where ==4)
{
++k;
}
if(where ==3)
{
++j;
–k;
}
if(where ==2)
{
++i;
–j;
}
/*if(k==length)
{
–k;
–j;
}*/
Ipaddress(intArray , i , j , k , length);
}
catch(ArrayIndexOutOfBoundsException e){
//System.out.println(“Exception thrown  :” + e);
}
}
static int createIP(int [] intArray , int start , int end)
{
//System.out.println(“I am at createIP()start = “+start+”\tend = “+end);
int val = 1 , fina = 0;
for(int e =end ; e>start ; –e)
{
fina = intArray[e]*val + fina;
val = val*10;
}
return fina;
}
}

Constant In C

A C constant is usually just the written version of a number. For example 1, 0, 5.73, 12.5e9. We can specify our constants in octal or hexadecimal, or force them to be treated as long integers.
  • Octal constants are written with a leading zero – 015.
  • Hexadecimal constants are written with a leading 0x – 0x1ae.
  • Long constants are written with a trailing L – 890L.

Character constants are usually just the character enclosed in single quotes; ‘a’, ‘b’, ‘c’. Some characters can’t be represented in this way, so we use a 2 character sequence as follows.

'\n' newline
'\t' tab
'\\' backslash
'\'' single quote
'\0' null ( Usedautomatically to terminate character string )
In addition, a required bit pattern can be specified using its octal equivalent.
‘\044’ produces bit pattern 00100100.
Character constants are rarely used, since string constants are more convenient. A string constant is surrounded by double quotes eg “Brian and Dennis”. The string is actually stored as an array of characters. The null character ‘\0’ is automatically placed at the end of such a string to act as a string terminator.
A character is a different type to a single character string. This is important poing to note.

Defining Constants

ANSI C allows you to declare constants. When you declare a constant it is a bit like a variable declaration except the value cannot be changed.
The const keyword is to declare a constant, as shown below:
int const a = 1;
const int a =2;
Note:
  • You can declare the const before or after the type. Choose one an stick to it.
  • It is usual to initialise a const with a value as it cannot get a value any other way.
The preprocessor #define is another more flexible (see Preprocessor Chapters) method to define constants in a program.
#define TRUE  1
#define FALSE 0
#define NAME_SIZE 20
Here TRUE, FALSE and NAME_SIZE are constant
You frequently see const declaration in function parameters. This says simply that the function is not going to change the value of the parameter.
The following function definition used concepts we have not met (see chapters on functions, strings, pointers, and standard libraries) but for completenes of this section it is is included here:
void strcpy(char *buffer, char const *string)

The enum Data type

enum is the abbreviation for ENUMERATE, and we can use this keyword to declare and initialize a sequence of integer constants. Here’s an example:
enum colors {RED, YELLOW, GREEN, BLUE};
I’ve made the constant names uppercase, but you can name them which ever way you want.
Here, colors is the name given to the set of constants – the name is optional. Now, if you don’t assign a value to a constant, the default value for the first one in the list – RED in our case, has the value of 0. The rest of the undefined constants have a value 1 more than the one before, so in our case, YELLOW is 1GREEN is 2 and BLUE is 3.
But you can assign values if you wanted to:
enum colors {RED=1, YELLOW, GREEN=6, BLUE };
Now RED=1, YELLOW=2, GREEN=6 and BLUE=7.
The main advantage of enum is that if you don’t initialize your constants, each one would have a unique value. The first would be zero and the rest would then count upwards.
You can name your constants in a weird order if you really wanted…
#include 

int main() {
enum {RED=5, YELLOW, GREEN=4, BLUE};

printf("RED = %d\n", RED);
printf("YELLOW = %d\n", YELLOW);
printf("GREEN = %d\n", GREEN);
printf("BLUE = %d\n", BLUE);
return 0;
}

This will produce following results

RED = 5
YELLOW = 6
GREEN = 4
BLUE = 5

Copied From Tutorial C

Difference between Near , Far and Huge Pointer

as we know by default the pointers are near for example int *p is a near pointer… size of near pointer is 2 bytes in case of 16 bit compiler…….. n we already know very well size varies compiler to compiler…… They only store the offset of the address the pointer is referencing. . An address consisting of only an offset has a range of 0 – 64K bytes…. i think there is no need to discuss near pointers anymore…. so come to the main point….. that is far and huge pointers……


far and huge pointers:
Far and huge pointers have a size of 4 bytes. They store both the segment and the offset of the address the pointer is referencing. thn what is the difference between them ………..

Limitation of far pointer:
We cannot change or modify the segment address of given far address by applying any arithmetic operation on it. That is by using arithmetic operator we cannot jump from one segment to other segment. If you will increment the far address beyond the maximum value of its offset address instead of incrementing segment address it will repeat its offset address in cyclic order. this is also called wrapping…..i.e. if offset is 0xffff and we add 1 then it is 0x0000 and similarly if we decrease 0x0000 by 1 then it is 0xffff and remember there is no change in the segment….

Now i am going to compare huge and far pointers……….

1.
When a far pointer is incremented or decremented ONLY the offset of the pointer is actually incremented or decremented but in case of huge pointer both segment and offset value will change…..
like if we have

int main()
{
char far* f=(char far*)0x0000ffff;
printf(“%Fp”,f+0x1);
return 0;
}

then the output is:
0000:0000

as we see there is no change in segment value…….

and in case of huge……..


int main()
{
char huge* h=(char huge*)0x0000000f;
printf(“%Fp”,h+0x1);
return 0;
}
then the o/p is:
0001:0000

it shows bcoz of increment operation not only offset value but segment value also change………. that means segment will not change in case of far pointers but in case of huge it can move from one segment to another ……
2.
When relational operators are used on far pointers only the offsets are compared.In other words relational operators will only work on far pointers if the segment values of the pointers being compared are the same. and in case of huge this will not happen, actually comparison of absolute addresses takes place…... lets understand with the help of an example…
in far………………………….

int main()
{
char far * p=(char far*)0x12340001;
char far* p1=(char far*)0x12300041;
if(p==p1)
printf(“same”);
else
printf(“different”);
return 0;
}

Output:
different
in huge…………………..

int main()
{
char huge * p=(char huge*)0x12340001;
char huge* p1=(char huge*)0x12300041;
if(p==p1)
printf(“same”);
else
printf(“different”);
return 0;
}


Output:
same

Explanation:
as we see the absolute address for both p and p1 is 12341 (1234*10+1 or 1230*10+41) but they are not considered equal in 1st case becoz in case of far pointers only offsets are compared i.e. it will check whether 0001==0041…. that we know is false…. and know see what will happen in case of huge…..the comparison operation is performed on absolute addresses that are equal as i already told……
3.
A far pointer is never noramlized but a huge pointer is normalized . A normalized pointer is one that has as much of the address as possible in the segment, meaning that the offset is never larger than 15.
suppose if we have 0x1234:1234 then the normalized form of it is 0x1357:0004(absolute address is 13574)…….
A huge pointer is normalized only when some arithmetic operation is performed on it … and not noramlized during assignment….
int main()
{
char huge* h=(char huge*)0x12341234;
char huge* h1=(char huge*)0x12341234;
printf(“h=%Fp\nh1=%Fp”,h,h1+0x1);
return 0;
}
Output:
h=1234:1234
h1=1357:0005
Explanation:
as i said above huge is not normalized in case of assignment……but if an arithmetic operation is performed on it ….. it will be normalized…. so h is 1234:1234 and h1 is 1357:0005……….that is normalized…….
4.
The offset of huge pointer is less than 16 because of normalization and not so in case of far pointers……………….
lets take an example to understand what i want to say…..
int main()
{
char far* f=(char far*)0x0000000f;
printf(“%Fp”,f+0x1);
return 0;
}
Output:
0000:0010
in case of huge
int main()
{
char huge* h=(char huge*)0x0000000f;
printf(“%Fp”,h+0x1);
return 0;
}

Output:
0001:0000
Explanation:
as we increment far pointer by 1 it will be 0000:0010…… and as we increment huge pointer by 1 thn it will be 0001:0000 bcoz its offset cant be greater than 15 in other words it will be normalized…………
Copied from C Stuff 

SSD vs HDD

This is era of the Ultrabook Laptops .. as we know in UltraBook there is no HDD like Hard Disk there is new technology Called SSD(Solid State Drive ) .. which more faster than HDD … lets check it out ..
These days most people are buying laptops for their computing needs and you have to make the decision between getting either a Solid State Drive (SSD) or Hard Disk Drive (HDD) as the storage component. So which is best to get, a SSD or HDD?  There’s no straight forward answer to this question, each buyer has different needs and you have to evaluate the decision based on those needs, your preferences, and of course budget.  Even though the price of SSDs has been falling and right now there is a tight supply of HDD drives due to Thailand floods, the price advantage is still strongly with HDDs.  But if performance and fast bootup is your top consideration, and money is secondary, then SSD is the way to go.  We’ll make a comparison of SSD and HDD storage and go over the good, the bad and the ugly of both.
What is a SSD?
We’ll make no assumptions here and keep this article on a level that anyone can understand.  You might be shopping for a computer and simply wondering what the heck SSD actually means?  To begin, SSD stands for Solid State Drive.  You’re probably familiar with USB memory sticks, SSD can be thought of as an oversized and more sophisticated version of the humble USB memory stick.  Like a memory stick, there are no moving parts to an SSD, information is stored in microchips.  Meanwhile, a hard drive uses a mechanical arm with a read/write head to move around and read information from the right location on a storage platter.  This difference is what makes SSD so much faster.  As an analogy, what’s quicker, having to walk across the room to retrieve a book to get information or simply magically having that book open in front of you when you need it?  That’s how an HDD compares to an SSD, it simply requires more physical labor (mechanical movement) to get information.
A typical SSD uses what is called NAND-based flash memory, this is a non-volatile type of memory.  What does non-volatile mean you ask?  The simple answer is that you can turn off the disk and it won’t “forget” what was stored on it.  This is of course an essential characteristic of any type of permanent memory.  During the early days of SSD rumors floated around saying stored data would wear off and be lost after only a few years.  Today this is not true, you can read and write to an SSD all day long and the data storage integrity will be maintained for well over 200 years.  In other words, the data storage life of an SSD can outlive you!
An SSD does not have a mechanical arm to read and write data, it instead relies on an embedded processor (or “brain”) called a controller to perform a bunch of operations related to reading and writing data.  The controller is a very important factor in determining the speed of the SSD, decisions it makes related to how to store, retrieve, cache and clean up data can determine the overall speed of the drive.  We won’t get into the nitty gritty of the details for the various tasks it performs such as error correction, read and write caching, encryption and garbage collection to name a few but suffice to say, good controller technology is often what separates an excellent from simply good SSD.  An example of a fast controller today is the SandForce SATA 3.0 (6 Gb/s) SSD controller that supports up to 500 MB per second read and write speeds.
Finally, you may be wondering what an SSD looks like and how easy it is to replace a hard drive with after market.  If you look at the images below you’ll see the top and underside of a typical sized 2.5” SSD, the technology is encased inside either a plastic or metal case and so it looks like nothing more than a battery might look like:
SSD Top Side
SSD Bottom Side
The form factor of the SSD is actually the same as a regular hard drive, it comes in a standard 1.8”, 2.5” or 3.5” size that can fit into the housing and connectors for the same sized hard drives.  The connector used for these standard sizes is SATA, there are smaller SSDs available that use what’s called mini-SATA (mSATA) and fit into the mini-PCI Express slot of a laptop.
What is an HDD?
Hard Disk Drives, or HDD in techno-parlance, have been around for donkeys years relative to the technology world.  HDDs were first introduced by IBM in 1956, yes folks this is nearly 60-year old technology, thank goodness vacuum tubes for TVs didn’t last so long!  An HDD uses magnetism to store data on a rotating platter.  A read/write head floats above the spinning platter reading and writing data.  The faster the platter spins, the faster an HDD can perform, typical laptop drives today spin at either 5400 RPM (Revolutions per Minute) or 7200RPM, some server based platters can spin at up to 15,000 RPM.
The major advantage of an HDD is that it is capable of storing lots of data cheaply.  These days 1 TeraByte (1,024 gigabytes) of storage is not unusual for a laptop hard drive, and the density continues to grow.  Cost per gigabyte is only around $0.10 / GB these days for an HDD, that’s amazing when you compare it to the near $1.75 / GB cost for an SSD.  If you want cheap storage and lots of it, using a standard hard drive is definitely the more appealing way to go.
HDDs predominantly use the SATA interface.  The most common size for laptop hard drives is the 2.5” form factor while a larger 3.5” form factor is used in desktop computers.  The larger size allows for more platters inside and thus more storage capacity.  Some desktop hard drives can store up to 4TB of data! HDDs look essentially the same from the outside as an SSD, below is an example of what an HDD looks like using the Seagate Barracuda 3TB hard drive:
HDD Top Side
HDD Bottom Side
SSD Vs HDD Comparison
Now it’s time to do some comparisons and determine which might be best for  your needs, an SSD or HDD?  The best way to compare items is a table with a side by side comparison of items in which a green box indicates an advantage:
Attribute SSD (Solid State Drive) HDD (Hard Disk Drive)
Power Draw / Battery Life Less power draw, averages 2 – 3 watts, resulting in 30+ minute battery boost More power draw, averages 6 – 7 watts and therefore uses more battery
Cost Expensive, in excess of $1.50 per gigabyte Only around $0.10 per gigabyte, very cheap
Capacity Typically not larger than 256GB for notebook size drives Typically 500GB – 1TB for notebook size drives
Bootup Time for Windows 7 Around 22 seconds average bootup time Around 40 seconds average bootup time
Noise There are no moving parts and as such no sound Audible clicks and spinning can be heard
Vibration No vibration as there are no moving parts The spinning of the platters can sometimes result in vibration
Heat Produced Lower power draw and no moving parts so little heat is produced HDD doesn’t produce much heat, but it will have a measurable amount more heat than an SSD due to moving parts and higher power draw
Failure Rate Mean time between failure rate of 2.0 million hours Mean time between failure rate of 1.5 million hours
File Copy / Write Speed Generally above 200 MB/s and up to 500 MB/s for cutting edge drives The range can be anywhere from 50 – 120MB / s
Encryption Full Disk Encryption (FDE)Supported on some models Full Disk Encryption (FDE) Supported on some models
File Opening Speed Up to 30% faster than HDD Slower than SSD
Magnetism Affected? An SSD is safe from any effects of magnetism Magnets can erase data
If we tally up the checkmarks the SSD gets 9 and HDD gets 3.  Does that mean the that an SSD is three times better than an HDD?  Not at all, it depends on your needs, the comparison here is just to lay out what the pros and cons are for each.  Here are some rules to follow in deciding which drive is best for you:
If:
  • You need lots of storage capacity, over 500GB
  • Don’t want to spend much money
  • Don’t care too much about how fast a computer boots up or opens programs then get a hard drive.
If:
  • You are willing to pay for faster performance
  • Don’t mind limited storage capacity or can work around that then get an SSD.

this Article is Copied from Storage Reviews