1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hint.cpp 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
charlie 提交于 2024-01-09 00:01 . move from github to gitee
#include <iostream>
#include <string>
using namespace std;
struct hp{
string int_part="0",decimal_part="0";
const int base='0';
//判断变量是否存在小数部分
bool decimal(){
if(decimal_part == "0")
return false;
else
return true;
}
//加法(整数型)
hp operator + (int addend){
int p=0,i=int_part.length()-1;
hp ans;
ans.int_part = int_part;
while((addend != 0 || p != 0) && i >= 0){
int head;
head = addend%10+p+(int_part[i]-base);
ans.int_part[i] = char(head%10+base);
addend = addend/10;
p = head/10;
i--;
}
addend += p;
while(addend != 0){
string head;
head = char(addend%10+base);
ans.int_part = head+ans.int_part;
addend = addend/10;
}
return ans;
}
//减法(整数型)
hp operator - (int subtractor){
int p=0;
hp ans;
}
//乘法(整数型)
hp operator * (int multiplier){
int p=0;
hp ans;
ans.int_part = int_part;
for(int i=ans.int_part.length()-1;i>=0;i--){
int l=ans.int_part[i]-base;
l = l*multiplier+p;
ans.int_part[i] = char(l%10+base);
p = l/10;
}
while(p != 0){
string head;
head = char(p%10+base);
ans.int_part = head+ans.int_part;
p = p/10;
}
return ans;
}
};
//
//int main(){
// hp h;
// h.int_part="7890123456";
// h = h+3;
// cout<<h.int_part;
// h = h+9;
// cout<<endl<<h.int_part;
// h = h;
// return 0;
//}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/saigonshu/algorithm.git
git@gitee.com:saigonshu/algorithm.git
saigonshu
algorithm
Algorithms
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385