diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..50e51b7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.10) +project(BigInt) +add_subdirectory(data) +add_subdirectory(src) \ No newline at end of file diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt new file mode 100644 index 0000000..74ca77f --- /dev/null +++ b/data/CMakeLists.txt @@ -0,0 +1,7 @@ +set(PROJECT_NAME ${CMAKE_PROJECT_NAME}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_FLAGS "-g -O2") +include_directories(${PROJECT_SOURCE_DIR}/include) +link_directories(${PROJECT_SOURCE_DIR}/src) +add_executable(C1T1 Interger1/1.cpp) +target_link_libraries(C1T1 int2048) \ No newline at end of file diff --git a/include/int2048.h b/include/int2048.h new file mode 100644 index 0000000..3c18f13 --- /dev/null +++ b/include/int2048.h @@ -0,0 +1,87 @@ +#pragma once +#ifndef SJTU_BIGINTEGER +#define SJTU_BIGINTEGER + +// Integer 1: +// 实现一个有符号的大整数类,只需支持简单的加减 + +// Integer 2: +// 实现一个有符号的大整数类,支持加减乘除,并重载相关运算符 + +// 请不要使用除了以下头文件之外的其它头文件 +#include +#include +#include +#include +#include + +// 请不要使用 using namespace std; + +namespace sjtu { +class int2048 { + // todo + public: + // 构造函数 + int2048(); + int2048(long long); + int2048(const std::string &); + int2048(const int2048 &); + + // 以下给定函数的形式参数类型仅供参考,可自行选择使用常量引用或者不使用引用 + // 如果需要,可以自行增加其他所需的函数 + // =================================== + // Integer1 + // =================================== + + // 读入一个大整数 + void read(const std::string &); + // 输出储存的大整数,无需换行 + void print(); + + // 加上一个大整数 + int2048 &add(const int2048 &); + // 返回两个大整数之和 + friend int2048 add(int2048, const int2048 &); + + // 减去一个大整数 + int2048 &minus(const int2048 &); + // 返回两个大整数之差 + friend int2048 minus(int2048, const int2048 &); + + // =================================== + // Integer2 + // =================================== + + int2048 operator+() const; + int2048 operator-() const; + + int2048 &operator=(const int2048 &); + + int2048 &operator+=(const int2048 &); + friend int2048 operator+(int2048, const int2048 &); + + int2048 &operator-=(const int2048 &); + friend int2048 operator-(int2048, const int2048 &); + + int2048 &operator*=(const int2048 &); + friend int2048 operator*(int2048, const int2048 &); + + int2048 &operator/=(const int2048 &); + friend int2048 operator/(int2048, const int2048 &); + + int2048 &operator%=(const int2048 &); + friend int2048 operator%(int2048, const int2048 &); + + friend std::istream &operator>>(std::istream &, int2048 &); + friend std::ostream &operator<<(std::ostream &, const int2048 &); + + friend bool operator==(const int2048 &, const int2048 &); + friend bool operator!=(const int2048 &, const int2048 &); + friend bool operator<(const int2048 &, const int2048 &); + friend bool operator>(const int2048 &, const int2048 &); + friend bool operator<=(const int2048 &, const int2048 &); + friend bool operator>=(const int2048 &, const int2048 &); +}; +} // namespace sjtu + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..22fa710 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,5 @@ +set(PROJECT_NAME ${CMAKE_PROJECT_NAME}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_FLAGS "-g -O2") +include_directories(${PROJECT_SOURCE_DIR}/include) +add_library(int2048 STATIC int2048.cpp) \ No newline at end of file diff --git a/src/int2048.cpp b/src/int2048.cpp new file mode 100644 index 0000000..e69de29