版本比较
C++plus
正文
增加 114 行删除 135 行
1234567891011408 行未改动全部展开420421422423424425426427428145 行未改动全部展开57457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671714 行未改动732733734735736737738739444 行未改动全部展开118411851186118711881189119011911192119311941195## 前言起因:这些东西好麻烦。中间忘了,然后就有了它。功能无法做到完全优秀或正确,欢迎私信反馈。## 正文### 编译选项408 行未改动全部展开请把主函数改为```cpp line-numberssigned main(){return 0;}```145 行未改动全部展开请不要在程序中删除它。:::### To-do list- [ ] 私有成员函数在类外部的使用。- [x] 纯实数或纯虚数的使用。### 测试用此部分与正文无关,仅用于作者测试相关功能。:::info[测试]```cpp line-numbersvoid test() {cout << "=== frint 高精度整数类测试 ===" << endl;// 基本测试cout << "\n1. 基本构造函数和输出测试:" << endl;frint a("12345678901234567890");frint b("98765432109876543210");frint c(-123456);frint d = 999999999;cout << "a = " << a << endl;cout << "b = " << b << endl;cout << "c = " << c << endl;cout << "d = " << d << endl;// 算术运算测试cout << "\n2. 算术运算测试:" << endl;cout << "a + b = " << a + b << endl;cout << "b - a = " << b - a << endl;cout << "a * b = " << a * b << endl;cout << "b / a = " << b / a << endl;cout << "b % a = " << b % a << endl;// 负数运算测试cout << "\n3. 负数运算测试:" << endl;frint e("-123456789");frint f("987654321");cout << "e = " << e << endl;cout << "f = " << f << endl;cout << "e + f = " << e + f << endl;cout << "e - f = " << e - f << endl;cout << "e * f = " << e * f << endl;cout << "f / e = " << f / e << endl;// 复合赋值测试cout << "\n4. 复合赋值运算测试:" << endl;frint g("1000000000000000000");frint h("3");g += h;cout << "g += 3: " << g << endl;g *= frint("2");cout << "g *= 2: " << g << endl;g /= frint("7");cout << "g /= 7: " << g << endl;// 比较运算测试cout << "\n5. 比较运算测试:" << endl;cout << "a < b: " << (a < b) << endl;cout << "a > b: " << (a > b) << endl;cout << "a == b: " << (a == b) << endl;cout << "a != b: " << (a != b) << endl;cout << "e < f: " << (e < f) << endl;// 递增递减测试cout << "\n6. 递增递减测试:" << endl;frint i("999999999999999999");cout << "i = " << i << endl;cout << "++i = " << ++i << endl;cout << "i++ = " << i++ << endl;cout << "i after i++ = " << i << endl;cout << "--i = " << --i << endl;cout << "i-- = " << i-- << endl;cout << "i after i-- = " << i << endl;// 大数性能测试cout << "\n7. 大数运算性能测试:" << endl;frint j("1" + string(100, '9')); // 101位数字frint k("1234567890");auto start = chrono::high_resolution_clock::now();frint l = j * k;auto end = chrono::high_resolution_clock::now();auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);cout << "100位数字 * 10位数字: " << duration.count() << " ms" << endl;// 异常处理测试cout << "\n8. 异常处理测试:" << endl;try {frint zero("0");frint result = a / zero;cout << "Should not reach here!" << endl;} catch (const runtime_error& err) {cout << "Caught exception: " << err.what() << endl;}// Complex类测试cout << "\n=== Complex 复数类测试 ===" << endl;Complex c1("3+4i");Complex c2("1+2i");Complex c3("-5-6i");cout << "\n1. 复数基本运算:" << endl;cout << "c1 = " << c1 << endl;cout << "c2 = " << c2 << endl;cout << "c3 = " << c3 << endl;cout << "c1 + c2 = " << c1 + c2 << endl;cout << "c1 - c2 = " << c1 - c2 << endl;cout << "c1 * c2 = " << c1 * c2 << endl;cout << "c1 / c2 = " << c1 / c2 << endl;cout << "\n2. 复数共轭和模平方:" << endl;cout << "conj(c1) = " << c1.conj() << endl;cout << "|c1|^2 = " << c1.mod2() << endl;cout << "\n3. 复数输入测试(请输入复数,如 5+3i 或 -2-4i): ";Complex c4;cin >> c4;cout << "你输入的复数是: " << c4 << endl;// 混合运算测试cout << "\n4. 混合运算测试:" << endl;Complex c5 = c1 * c2 + c3;cout << "c1 * c2 + c3 = " << c5 << endl;cout << "\n5. 大数复数测试:" << endl;Complex big1("12345678901234567890+98765432109876543210i");Complex big2("11111111111111111111+22222222222222222222i");cout << "big1 = " << big1 << endl;cout << "big2 = " << big2 << endl;cout << "big1 + big2 = " << big1 + big2 << endl;cout << "big1 * big2 = " << big1 * big2 << endl;cout << "\n=== 所有测试完成 ===" << endl;}```该测试函数使用deepseek-R1生成。14 行未改动#include <cmath>#include <stdexcept>#define str string#define float doubleusing namespace std;class frint{private:str v;444 行未改动全部展开return*this;}};signed main(){return 0;}```:::最后,感谢洛谷的所有模板题让我减少了很多工作量。12345678910111213408 行未改动全部展开422423424425426427428429430145 行未改动全部展开57657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669714 行未改动712713714715716717718719720444 行未改动全部展开1165116611671168116911701171117211731174- [C++plus文档地址](https://www.luogu.com.cn/article/ykup0ycs)(洛谷)。## 前言起因:这些东西好麻烦。中间忘了,然后就有了它。欢迎私信反馈qwq## 正文### 编译选项408 行未改动全部展开请把主函数改为```cpp line-numberssigned main(){return 0;}```145 行未改动全部展开请不要在程序中删除它。:::### 测试用此部分与正文无关,仅用于笔者测试相关功能。:::info[测试]```cpp line-numbers//void test() {// cout << "=== frint 高精度整数类测试 ===" << endl;// // 基本测试// cout << "\n1. 基本构造函数和输出测试:" << endl;// frint a("12345678901234567890");// frint b("98765432109876543210");// frint c(-123456);// frint d = 999999999;// cout << "a = " << a << endl;// cout << "b = " << b << endl;// cout << "c = " << c << endl;// cout << "d = " << d << endl;// // 算术运算测试// cout << "\n2. 算术运算测试:" << endl;// cout << "a + b = " << a + b << endl;// cout << "b - a = " << b - a << endl;// cout << "a * b = " << a * b << endl;// cout << "b / a = " << b / a << endl;// cout << "b % a = " << b % a << endl;// // 负数运算测试// cout << "\n3. 负数运算测试:" << endl;// frint e("-123456789");// frint f("987654321");// cout << "e = " << e << endl;// cout << "f = " << f << endl;// cout << "e + f = " << e + f << endl;// cout << "e - f = " << e - f << endl;// cout << "e * f = " << e * f << endl;// cout << "f / e = " << f / e << endl;// // 复合赋值测试// cout << "\n4. 复合赋值运算测试:" << endl;// frint g("1000000000000000000");// frint h("3");// g += h;// cout << "g += 3: " << g << endl;// g *= frint("2");// cout << "g *= 2: " << g << endl;// g /= frint("7");// cout << "g /= 7: " << g << endl;// // 比较运算测试// cout << "\n5. 比较运算测试:" << endl;// cout << "a < b: " << (a < b) << endl;// cout<< "a> b: " << (a > b) << endl;// cout << "a == b: " << (a == b) << endl;// cout << "a != b: " << (a != b) << endl;// cout << "e < f: " << (e < f) << endl;// // 递增递减测试// cout << "\n6. 递增递减测试:" << endl;// frint i("999999999999999999");// cout << "i = " << i << endl;// cout << "++i = " << ++i << endl;// cout << "i++ = " << i++ << endl;// cout << "i after i++ = " << i << endl;// cout << "--i = " << --i << endl;// cout << "i-- = " << i-- << endl;// cout << "i after i-- = " << i << endl;// // 大数性能测试// cout << "\n7. 大数运算性能测试:" << endl;// frint j("1" + string(100, '9')); // 101位数字// frint k("1234567890");// auto start = chrono::high_resolution_clock::now();// frint l = j * k;// auto end = chrono::high_resolution_clock::now();// auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);// cout << "100位数字 * 10位数字: " << duration.count() << " ms" << endl;// // 异常处理测试// cout << "\n8. 异常处理测试:" << endl;// try {// frint zero("0");// frint result = a / zero;// cout << "Should not reach here!" << endl;// } catch (const runtime_error& err) {// cout << "Caught exception: " << err.what() << endl;// }// // Complex类测试// cout << "\n=== Complex 复数类测试 ===" << endl;// Complex c1("3+4i");// Complex c2("1+2i");// Complex c3("-5-6i");// cout << "\n1. 复数基本运算:" << endl;// cout << "c1 = " << c1 << endl;// cout << "c2 = " << c2 << endl;// cout << "c3 = " << c3 << endl;// cout << "c1 + c2 = " << c1 + c2 << endl;// cout << "c1 - c2 = " << c1 - c2 << endl;// cout << "c1 * c2 = " << c1 * c2 << endl;// cout << "c1 / c2 = " << c1 / c2 << endl;// cout << "\n2. 复数共轭和模平方:" << endl;// cout << "conj(c1) = " << c1.conj() << endl;// cout << "|c1|^2 = " << c1.mod2() << endl;// cout << "\n3. 复数输入测试(请输入复数,如 5+3i 或 -2-4i): ";// Complex c4;// cin >> c4;// cout << "你输入的复数是: " << c4 << endl;// // 混合运算测试// cout << "\n4. 混合运算测试:" << endl;// Complex c5 = c1 * c2 + c3;// cout << "c1 * c2 + c3 = " << c5 << endl;// cout << "\n5. 大数复数测试:" << endl;// Complex big1("12345678901234567890+98765432109876543210i");// Complex big2("11111111111111111111+22222222222222222222i");// cout << "big1 = " << big1 << endl;// cout << "big2 = " << big2 << endl;// cout << "big1 + big2 = " << big1 + big2 << endl;// cout << "big1 * big2 = " << big1 * big2 << endl;// cout << "\n=== 所有测试完成 ===" << endl;//}```该测试函数使用deepseek-R1生成。14 行未改动#include <cmath>#include <stdexcept>#define str string#define float double#define endl '\n'using namespace std;class frint{private:str v;444 行未改动全部展开return*this;}};signed main(){return 0;}```:::