http://www.spoj.pl/problems/BISHOPS/
hey, Can any one please see this problem and tell me how to deal with number like 10^100 ? Please help me out as it is used in many many problems. thanks in advance to everyone.
http://www.spoj.pl/problems/BISHOPS/
hey, Can any one please see this problem and tell me how to deal with number like 10^100 ? Please help me out as it is used in many many problems. thanks in advance to everyone.
Jump to PostThere are a number of libraries that deal with large integers, such as GMP.
Jump to PostActually you can solve the bishop problem by hand, first try for samller numbers then generalize the result. Its a common math olympiad problem.
Anyways, returning to your question, you can handle such number by linked list. You have to develop your own way to do operations like add, subtract …
Jump to PostEnter it into a temporary input buffer. Then move it into place in your array.
np complete: you can handle such number by linked list.
Major overkill. Since the numbers must be kept sequential, why do you need a structure containing and int and a pointer and all …
Actually you can solve the bishop problem by hand, first try for samller numbers then generalize the result. Its a common math olympiad problem.
Anyways, returning to your question, you can handle such number by linked list. You have to develop your own way to do operations like add, subtract etc on it. There are libraries to help you handle large numbers. One of them is GMP. You may check this out.
can you tell me how to enter number in array in reverse oder. like i have char array of 100 , then i want the string to be shifted right in the array rather than left as usually is enters. thanks
I'm not entirely sure what you are asking. You can iterate through an array in reverse like this:
for(i = size_of_array - 1; i >= 0; i--) {
...
}
Or refer to the array like this:
array[size_of_array - 1 - index] = some_value;
no, what i actually wanyt is if i am entering 2345654345555556667777 in the character array , then if array size is 100, then 7 should be the 99th element of the array. i hope u gettng it now
Enter it into a temporary input buffer. Then move it into place in your array.
np complete: you can handle such number by linked list.
Major overkill. Since the numbers must be kept sequential, why do you need a structure containing and int and a pointer and all that code to insert/delete/traverse nodes?
A simple array is the answer...
Assuming the number is a string (since it is greater than a 64-bit unsigned integer), you could do something like this:
char *smallStr, *bigStr;
size_t index, offset;
smallStr = "2345654345555556667777";
bigStr = (char*)calloc(100, sizeof(char));
/* This copies the null terminator from smallStr. Change to "100 - strlen(smallStr);" if you do not want the null terminator. */
offset = 99 - strlen(smallStr);
for(index = 99; index >= offset; index--)
bigStr[index] = smallStr[index - offset];
/* Pad bigStr with 0's */
for(index = 0; index < offset; index++)
bigStr[index] = '0';
Hope that's what you meant...
@waltP is there any library in which i can handle these types of numbers? I mean rather than putting it into array, can't i use any pre-defined data types like java language have ? I seriously don't know if C has any libraries like that. thanks to you in advance.
Depends on what you need to do. If you want to use "pre-defined data types like java", use java. If you want to use C, you need to use the data types C has. Or find a third-party library, such as the one already mentioned.
Unless you wish to use libraries to proceed/switch to C++ to use the BigInteger class,you would have to implement all arithmetic on character arrays and operate on them carefully.It will take a whole lot of coding and wastage of time since it is already implemented in Java/C++.
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.