0

While solving a problem I realized that I had to store extremely large integers and that unsigned long long int couldn't store the answer. I read that this code could help me with this problem. But I am confused for two reasons.

I don't know how to actually use this file in another file that I'm using to solve a problem.

I don't know how a website like codeforces would accept a solution that uses a file that it doesn't have access to.

Ryan Marr
  • 83
  • 7
  • 1
    *But I am confused for two reasons.* -- I don't know what the confusion is. There is no built-in "big integer" type in C++, thus you have to write your own class to do it. You actually need to sit down and write the code to do the big integer work, and that site already "typed in" the code -- you just would copy / paste it. – PaulMcKenzie Jun 20 '19 at 04:33
  • Just copy the code into you project. – goodvibration Jun 20 '19 at 04:37
  • Be careful using code that you do not understand. When things go wrong, and the often do, you do not have a basis in which you can build the expectations needed to debug it – user4581301 Jun 20 '19 at 05:05

1 Answers1

0

CodeForces and other OJ will not accept including any other files or headers except from compiler's included header. So you cannot use it by importing from another file in OJ.

But if you want to use it locally you can do that. For that download or copy the content of Bigint.cpp to your source's location. Maybe like mine.

├── bigint.h
└── main.cpp

Note: I renamed Bigint.cpp to bigint.h

Then you can write your code in main.cpp (or whatever you want). Just include it as an header. Maybe something like this.

   1 #include <bits/stdc++.h>
   2 
   3 using namespace std;
   4 
   5 #include "bigint.h"
   6 
   7 int main (){
   8     bigint b(1000);
   9     cout << b.size() << endl;
  10     return 0;
  11 }

To use it in problem solving you just have to copy the entire code into your source file [After defining namespace and including headers]. Like the comment suggests don't just blindly use others' codes. Read through the code to understand.

exilour
  • 516
  • 5
  • 12
  • Please do not use `#include ` and avoid using `using namespace std;` in answers. The first is a terrible idea for [a number of reasons](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) and the second makes the worst effects of the first far more likely to strike home. – user4581301 Jun 20 '19 at 05:58
  • Sidenote: code not written with the intent for it to be a header and included will often have nasty effects like [ODR violations](https://en.cppreference.com/w/cpp/language/definition) when used as a header. Exercise caution when adapting this answer. – user4581301 Jun 20 '19 at 06:14
  • @user4581301 I understand your concern. But I didn't read the Bigint structure to know what structures it used. So using `` seemed "OKAY" for an example handler. Thanks for your suggestions. – exilour Jun 20 '19 at 06:57