首页 > 编程知识 正文

bigdecimal判断相等,biginteger取值范围

时间:2023-05-03 21:50:29 阅读:50820 作者:4278

1 % 2f % 2a 98765432109876542345234522147483452214834523452345234523147345234523452345234523452345234523452345234526、6098760914444、2223444444444 452345418176091476091434274 % 0a6% 20 % 23 include % 0a7% 20 % 23 include % 0a8% 20 % 23 include % 0a9% 20 % 23 include % 0a 0 %0a13 % 20 % 23 include % 0a 14 % 20 % 23 include % 0a 16 % 20 using % 20 namespaces TD % ef % BC % 9b % 2017 % 0a 18 structbiginter % e9 % 9d % 99 % E7 % 9a % 84 % E3 % 83 % a1 % E3 % B3 % 83 % 90 % E3 % 83 % BC % E5 % a4 % 89 % E6 % 95 % B0-- - 3 % 80 % 81 % E5 % BD % BC % E3 % 81 % AE % E6 % a7 % 8b % e9 % 80 % A0 % E4 % BD % 93 % E5 % 89 % E6 % 95 % B0 % E3 % 81 t % 20 width % 20 % 3d % 208 % ef % BC % 9b % 2021 % 20s % ef % BC % 9b % 20 % 2f % E5 % a4 % a7 % E3 % 81 % 8d % 8b % 0a 22 % 0a 23 big integer % ef % BC % 88长long num % 3d0% ef % BC % 89 % ef % BC % 89 % 2f % 2f % E3 % 82 % B3 % E3 % 83 7 % E3 % 83 % 95 % E3 % 82 % a9 % E3 % 83 % E3 % 88 % E4 % bb % 98 % E3 % 81 % 8d % ef % BC % 89 % ef % BC % 89 % ef gintegeroperator % 3d % ef % BC % 88 longlong num % ef % BC % 89 long % 20 long % E4 % bb % a5 % E4 % b8 % E3 % 81 % AE % E6 a27 % 20s.clear % ef % BC % 88 % ef % BC % 9b % 20 % 2f % E6 % 9c % AC % E3 % 82 % aa % E3 % 83 % 96 % E3 % 82 % b8 % ee % AE % B9 % E5 % 99 % A8 % E3 % 81 % AE % E5 % 86 % 85 % E5 % AE % B9 % 82 % E7 % a9 % ba % E3 % 81 % ab % E3 % 81 % AE % E5 % BD % B1 % e9 % 9f % BF % E3 % 81 % 8c % E3 % 81 % aa % E3 % 81 % 84 % E3 % 88 % E3 % 81 % 86 % E3 % 81 % ab28 % % a1 % 81 % E3 % 83 % bb % E5 % 85 % ab % E6 % a1 % 81 % E3 % 82 % E3 % 83 % E3 % 82 % af % E3 % 82 % BF % E3 % 83 % c % 88 num % base % ef % BC % 89 % ef % BC % 9b % 20 % 2f % E6 % 95 % B4 % E6 % E3 % 81 % 8c9% E6 % a1 % 81 % ee % E3 % 81 % 8c % E5 % be % 97 % E3 % 82 % 89 % E3 % 82 % 8c % E3 % 81 % 9f % 0a 31 % 20 num % 20 % 2f % 3d % 20 base % ef % BC % 84 % E7 % B6 % 9a % E3 % 81 % 91 % E3 % 82 % 8b % 0a 32 % ef % BC % 89 while % ef % BC % 88 num0% ef % BC % 89 % ef % BC % 9b % % 81 % ab % E6 % 88 % bb % E3 % 82 % 8b % 0a 35 % 2f % 2f longlong % E3 % 82 % BF % E3 % 82 % a4 % E3 % 83 % 97 % E3 % 81 % 8c % rator % 3d % ef % BC % 88 conststringstr % ef % BC % 89 % 2f % E4 % bb % a3 % E5 % 85 % a5 % E6 % BC % 94 % E7 % AE % 97 % % 3d % ef % BC % 88 str.length % ef % BC % 88-1 % ef % BC % 89 % 2f % 20 width % 20 % 20 % 201 % ef % BC % 9b % 20 % 2f %2ff % 84 % E3 % 81 % 8f % E3 % 81 % a4 % E3 % 81 % 81 % 82 % E3 % 82 % 8b % ef % BC % 88 % ef % BC % 89 % E4 % BD % 99 % % 88 % 87 % E3 % 82 % 8a % E6 % 8d % A8 % E3 % 81 % a6 % E3 % 82 % 8b % ef % BC % 89 % ef % BC % 89 % 2f % 2f % E5 % 8f % B3 % 6 % A0 % BC % E7 % B4 % 8d % E6 % 95 % B4 % E6 % 95 % B0 % E3 % 82 % E3 % 83 % 82 % af % E3 % 82 % BF % E3 % 83 % 88 % ef % BC % 89 % 2f % 2f % E5 % 85 % A8 % e9 % 83 % A8 % E3 % 81 % a78 % E3 % 83 % 83 % E3 % 83 % 83 % 88 % E3 % 88 % E3 % 8f % E3 % 81 % a4 % E3 % 81 % 8b % E3 % 82 % bb % E3 % 83 % E3 % 83 % 88 % 0a 41 intend % 3d str.length % ef % BC % 88 - 3 % 86 % E3 % 83 % 83 % 83 % 88 % E3 % 82 % 92 % E4 % b8 % 80 % E7 % b5 % 84 % E3 % 81 % ab % E3 % 81 % 99 % E3 % 82 % 8b % 8b % E3 % 81 % AE % E3 % 82 % aa % E3 % 82 % af % E3 % 83 % 83 % 83 % E3 % 83 % 83 % 3d % E5 % 89 % 8d % E3 % 81 % 8c % E5 % 89 % 8d % E3 % 81 % AE % E6 % a1 % 81 % E6 % 95 % B0-% 208 % E5 % 80 % 8b % E3 % 81 % AE % e9 % 95 % B7 % E3 % 81 % E3 % 82 % 8a % E3 % 81 % AE % E6 % a1 % 81 % E6 % 95 % B0 % E3 % 81 % E3 % 81 % a7 % E3 % 81 % aa % E3 % 81 % 91 % E3 % 8b % 0a 43 intstart % 3d max % ef % BC % 880 % ef % BC %8cend-width % ef % BC % 89 % ef % BC % 9b % 2044 % 20 % 2f % 2f % E3 % 99 % E3 % 82 % B9 % E3 % 82 % BF % E3 % 83 % E3 % 83 % 88 % E4 % BD % 8d % E7 % BD % E3 % 81 % ab % E3 % 81 % aa % 81 % a3 % E3 % 81 % 9f % E5 % A0 % B4 % E5 % 90 % 88 % E3 % 80 % 81结束-开始% 20 % 3d % 20 width % E3 % 81 % af8 % E6 % a1 % 4 % a2 % E6 % 96 % 87 % E5 % ad % 97 % E5 % 88 % 97 % E3 % 81 % AE % e9 % 95 % B7 % E3 % 81 % 9545 % 20 % 2f % 2f扫描% ef % 81 % AE % E5 % BD % a2 % E3 % 81 % a7 % E5 % 8f % 96 % E3 % 82 % 8a % E5 % 87 % ba % E3 % 81 % E3 % 81 % a6 % e9 % 81 % aa

>68 }69 returnc;70 }71

72 BigInteger operator += (const BigInteger &b)73 {74 *this = *this +b;75 return *this;76 }77

78

79 //比较运算符

80 bool operator < (const BigInteger &b) const

81 {82 if (s.size() !=b.s.size())83 return s.size() = 0; i--) //从后往前面比较,因为(低位在vector的前面)注:这样做的前提是两个

85 { //都没有前导0,否则不能比较

86 if (s[i] !=b.s[i])87 return s[i]

90 }91 bool operator > (const BigInteger &b) const

92 {93 return b < *this;94 }95 bool operator <= (const BigInteger &b) const

96 {97 return !(b < *this); //相当于返回 本对象 <= b对象

98 }99 bool operator >= (const BigInteger &b) const

100 {101 return !(*this

104 {105 return b < *this || *this

108 {109 return !(b < *this) || !(*this

113 ostream& operator << (ostream &out, const BigInteger &x)114 {115 out << x.s.back(); //从右向左输出(因为最高位是最后储存进去的)116 //八位八位的写

117 for (int i = x.s.size()-2; i >= 0; i--) { //从倒数第二位开始输出

118 char buf[20];119 sprintf(buf, "%08d", x.s[i]); //将整数当成字符写到buf中输出,不足八位的补零(因为在前面的几组八位中120 //如果不足八位说明在形成整数的过程中最高位为0)

121 for (unsigned int j = 0; j < strlen(buf); j++) //输出八位

122 out <

127 istream& operator >> (istream &in, BigInteger &x) {128 strings;129 if (! (in >>s))130 return in;131 x = s; //输入正确的流

132 return in;133 }134

135 structcmp {136 bool operator () (const BigInteger &a, const BigInteger &b) const { //升序比较

137 return a

141 structcmpL{142 bool operator () (const BigInteger &a, const BigInteger &b) const { //降序比较

143 return a >b;144 }145 };146 int main(void)147 {148 BigInteger bi, sum1, mus, b2;149

150 sets1;151

152 vectors2;153

154 maps3;155

156 pairs4;157

158 stringss;159 int i = 1;160

161 /*while (cin >> b2) //利用了重载 >> 提取运算符162 {163 mus += b2;164 }165 cout << mus << endl;*/

166

167 while (cin >>ss)168 {169 bi =ss;170 sum1 +=bi;171 s1.insert(bi);172 s2.push_back(bi);173 s4.first =bi;174 s4.second = 'a'+i; //用来检验map里面元素也是可以自动排序的175 i++;176 s3.insert(s4);177

178 }179

180 for (set::iterator it = s1.begin(); it != s1.end(); ++it) //set升序

181 cout << *it <

183 cout <

185 sort(s2.begin(),s2.end(),cmpL()); //sort 降序

186 for (vector::iterator it = s2.begin(); it != s2.end(); ++it)187 cout << *it <

189 for (map::iterator it = s3.begin(); it != s3.end(); ++it) //map降序

190 cout << (*it).second <

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。