求助:
P1601在洛谷上一直编译失败,但是在本地(windows10)MSVC c++20(优化不知道开没开)和g++.exe gunc++11(优化不知道开没开) 可以编译成功并且运行: (g++)
Compiling single file...
--------
- Filename: C:\cppcode\新建文件夹\Untitled1145.cpp
- Compiler Name: TDM-GCC 4.9.2 32-bit Release
Processing C++ source file...
--------
- C++ Compiler: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\g++.exe
- Command: g++.exe "C:\cppcode\新建文件夹\Untitled1145.cpp" -o "C:\cppcode\新建文件夹\Untitled1145.exe" -m32 -std=gnu++11 -D UNICODE -D _UNICODE -I"C:\Program Files (x86)\boost_1_83_0" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32" -static-libgcc -lgdi32 -lcomdlg32 -lpowrprof -lws2_32 -lcomctl32 -m32 -s
Compilation results...
--------
- Errors: 0
- Warnings: 0
- Output Filename: C:\cppcode\新建文件夹\Untitled1145.exe
- Output Size: 578 KiB
- Compilation Time: 0.86s
--------
114514
1919810
2034324
--------------------------------
Process exited after 4 seconds with return value 0
请按任意键继续. . .
(MSVC)
已启动生成...
1>------ 已启动生成: 项目: test0x20, 配置: Debug x64 ------
1>test0x20.cpp
1>test0x20.vcxproj -> C:\Users\frog\source\repos\test0x20\x64\Debug\test0x20.exe
========== 生成: 1 成功,0 失败,0 最新,0 已跳过 ==========
========= 生成 开始于 11:20,并花费了 01.320 秒 ==========
114514
1919810
2034324
C:\Users\?\source\repos\test0x20\x64\Debug\test0x20.exe (进程 23592)已退出,代码为 0。
按任意键关闭此窗口. . .
代码:
#include <iostream> // eht begin fo thing yna... again dna niaga
#include <string>
#include <numeric>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <cassert>
#include <bitset>
#include <queue>
#include <stack>
#include <functional>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#pragma warning(disable : 4996)
using namespace std;
namespace Number {
template<size_t size = 501>
class UZ {
protected:
char values[size] = { 0 };
size_t nsize;
public:
UZ(std::string str = "0") {
if (str == "0" || str == "") {
nsize = 0;
return;
}
size_t idx = 0;
for (size_t i = str.size(); i > 0; i--) {
values[idx++] = str[i - 1] ^ '0';
}
nsize = idx;
}
UZ(const UZ& right) {
memcpy(this->values, right.values, size);
this->nsize = right.nsize;
}
UZ& operator=(const UZ& right) {
if (this == &right) {
return *this;
}
memcpy(this->values, right.values, size);
this->nsize = right.nsize;
return *this;
}
UZ operator+(const UZ& right) {
UZ result{ *this };
result += right;
return result;
}
UZ& operator+=(const UZ& right) {
size_t max_size = std::max(this->nsize, right.nsize);
char carry = 0;
for (size_t i = 0; i < max_size || carry; ++i) {
if (i == this->nsize) {
this->nsize++;
}
this->values[i] += carry + (i < right.nsize ? right.values[i] : 0);
carry = this->values[i] >= 10;
if (carry) this->values[i] -= 10;
}
return *this;
}
void out() const {
for (size_t i = this->nsize; i > 0; i--) {
putchar(this->values[i - 1] ^ '0');
}
}
};
}
int main() {
string tmp;
cin >> tmp;
Number::UZ<> a{ tmp };
cin >> tmp;
Number::UZ<> b{ tmp };
(a + b).out();
}
注:#pragma warning(disable : 4996)不会有问题,我在做其他题的时候也会加这个,可以编译通过