封装高精莫名CE求调
  • 板块学术版
  • 楼主___njr___
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/12/5 21:10
  • 上次更新2023/12/6 07:11:07
查看原帖
封装高精莫名CE求调
602624
___njr___楼主2023/12/5 21:10
编译结果:
65		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque	In file included from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque
60		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack	                 from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack
200		C:\Users\99381\Desktop\cpp\bigint by byte.cpp	                 from C:\Users\99381\Desktop\cpp\bigint by byte.cpp
63	1	a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_construct.h	[Error] expected unqualified-id before 'namespace'
66		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque	In file included from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque
60		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack	                 from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack
200		C:\Users\99381\Desktop\cpp\bigint by byte.cpp	                 from C:\Users\99381\Desktop\cpp\bigint by byte.cpp
67	1	a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_uninitialized.h	[Error] expected unqualified-id before 'namespace'
67		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque	In file included from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque
60		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack	                 from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack
200		C:\Users\99381\Desktop\cpp\bigint by byte.cpp	                 from C:\Users\99381\Desktop\cpp\bigint by byte.cpp
69	1	a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_deque.h	[Error] expected unqualified-id before 'namespace'
69		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque	In file included from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\deque
60		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack	                 from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack
200		C:\Users\99381\Desktop\cpp\bigint by byte.cpp	                 from C:\Users\99381\Desktop\cpp\bigint by byte.cpp
59	1	a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\deque.tcc	[Error] expected unqualified-id before 'namespace'
62		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_stack.h	In file included from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_stack.h
61		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack	                 from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack
200		C:\Users\99381\Desktop\cpp\bigint by byte.cpp	                 from C:\Users\99381\Desktop\cpp\bigint by byte.cpp
35	1	a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\uses_allocator.h	[Error] expected unqualified-id before 'namespace'
61		a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack	In file included from a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\stack
200		C:\Users\99381\Desktop\cpp\bigint by byte.cpp	                 from C:\Users\99381\Desktop\cpp\bigint by byte.cpp
65	1	a:\dev-cpp\mingw32\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_stack.h	[Error] expected unqualified-id before 'namespace'
C:\Users\99381\Desktop\cpp\bigint by byte.cpp	In member function 'void Bigint<len>::out(Bigint<len>)':
245	2	C:\Users\99381\Desktop\cpp\bigint by byte.cpp	[Error] 'stack' was not declared in this scope
201	1	C:\Users\99381\Desktop\cpp\bigint by byte.cpp	[Note] 'std::stack' is defined in header '<stack>'; did you forget to '#include <stack>'?
245	8	C:\Users\99381\Desktop\cpp\bigint by byte.cpp	[Error] expected primary-expression before 'char'
246	17	C:\Users\99381\Desktop\cpp\bigint by byte.cpp	[Error] 's' was not declared in this scope
247	2	C:\Users\99381\Desktop\cpp\bigint by byte.cpp	[Error] 's' was not declared in this scope

#include<bitset>
#include<iostream>
#include<stack>
using namespace std;
template<typename _Ty>
inline _Ty minn(_Ty x, _Ty y) {
	return x < y ? x : y;
}
template<unsigned len>
class Bigint {
	std::bitset < len + 1 > val;
	inline Bigint<len> myself() {
		Bigint<len> x(val);
		return x;
	}
public:
	Bigint<len>(long long x = 0) {
		if (x >= 0) {
			val = x;
			val[len] = false;
		}
		else {
			val = (~x + 1);
			val[len] = true;
		}
	}
	Bigint<len>(bitset < len + 1 > x) {
		val = x;
	}
	inline Bigint<len> operator ~ () {
		return Bigint<len>(~val);
	}
	inline Bigint<len> operator<<(int x) {
		return Bigint<len>(val << x);
	}
	inline Bigint<len> operator>>(int x) {
		return Bigint<len>(val >> x);
	}
	inline Bigint<len> operator&(Bigint<len> x) {
		return Bigint<len>(val & x.val);
	}
	inline Bigint<len> operator|(Bigint<len> x) {
		return Bigint<len>(val | x.val);
	}
	inline Bigint<len> operator^(Bigint<len> x) {
		return Bigint<len>(val ^ x.val);
	}
	inline void operator=(Bigint<len> x) {
		val = x.val;
	}
	inline bool operator>(Bigint<len> x) {
		if (val[len] ^ x.val[len])return x.val[len];
		else if (val[len])return !(-myself() > -x);
		for (int i = len - 1; i >= 0; --i)if (val[i] ^ x.val[i])return val[i];
		return false;
	}
	inline bool operator<(Bigint<len> x) {
		return !(myself() >= x);
	}
	inline bool operator>=(Bigint<len> x) {
		return (myself() > x || myself() == x);
	}
	inline bool operator<=(Bigint<len> x) {
		return !(myself() > x);
	}
	inline bool operator==(Bigint<len> x) {
		for (int i = len; i >= 0; --i)if (val[i] ^ x.val[i])return false;
		return true;
	}
	inline bool operator!=(Bigint<len> x) {
		for (int i = len; i >= 0; --i)if (val[i] ^ x.val[i])return true;
		return false;
	}
	inline void operator++() {
		for (int i = 0; i <= len; ++i) {
			if (val[i]) {
				val[i] = false;
			}
			else {
				val[i] = true;
				return;
			}
		}
		return;
	}
	inline void operator--() {
		for (int i = 0; i <= len; ++i) {
			if (val[i]) {
				val[i] = false;
				return;
			}
			else {
				val[i] = true;
			}
		}
		return;
	}
	inline Bigint<len> operator -() {
		Bigint<len> x = ~myself();
		++x;
		return x;//????
	}
	inline void operator += (Bigint<len> x) {
		bool c = false;//??λ????
		for (int i = 0; i <= len; ++i)
			if (c) {
				if (val[i] ^ x.val[i]) {
					c = true;
					val[i] = false;
				}
				else if (!val[i]) {
					val[i] = true;
					c = false;
				}
			}
			else {
				if (val[i] ^ x.val[i]) {
					val[i] = true;
				}
				else if (val[i]) {
					val[i] = false;
					c = true;
				}
			}
	}
	inline void operator-=(Bigint<len> x) {
		Bigint<len> my = myself();
		my += (-x);
		val = my.val;
	}
	inline Bigint<len> operator*(Bigint<len> x) {
		Bigint<len> a, ans;
		a = myself();
		for (int i = 0; i <= len; ++i) {
			if (x.val[i])ans += a;
			a = a << 1;
		}
		return ans;
	}
	inline Bigint<len> operator+(Bigint<len> x) {
		Bigint<len> my = myself();
		my += x;
		return my;
	}
	inline Bigint<len> operator-(Bigint<len> x) {
		Bigint<len> my = myself();
		my -= x;
		return my;
	}
	inline void operator*=(Bigint<len> x) {
		val = (myself() * x).val;
	}
	inline Bigint<len> unsgn_div(Bigint<len>x) {
		Bigint<len> ans, l, r;
		l.val = 0;
		r = x;
		ans.val = 0;
		Bigint<len>tmp = myself();
		for (int i = 0; i <= len; ++i) {
			Bigint<len> mid = (l + r) >> 1;
			Bigint<len>mitmp = (mid * tmp);
			if (mitmp == x)return mid;
			else if (mitmp < x) ans = mid, l = mid + 1;
			else r = mid - 1;
		}
		return ans;
	}
	inline Bigint<len> operator /(Bigint<len>x) {
		if (x.val[len] && val[len])return (-myself() / -x);
		else if (x.val[len]) {
			return -(myself() / -x);
		}
		else if (val[len]) {
			return -(-myself() / x);
		}
		Bigint<len> ans = x.unsgn_div(myself());
		return ans;
	}
	inline void operator /= (Bigint<len> x) {
		val = (myself() / x).val;
	}
	inline Bigint<len> operator % (Bigint<len>x) {
		return myself() - ((myself() / x) * x);
	}
	inline Bigint<len> operator %=(Bigint<len>x) {
		val = (myself() % x).val;
	}
	inline long long to_llong() {
		long long ans = 0;
		for (int i = 0; i <= min(len - 1, 63u); ++i)ans = (ans << 1) + val[i];
		return ans;
	}
	inline char to_10_last_(Bigint<len> _10, Bigint<len> val[10]) {
		auto c = myself() % _10;
		for (int i = 0; i < 10; ++i)
			if (val[i] == c)
				return i ^ 48;
	}
	inline void oudddt() {
		cout << val;
	}
	inline bool operator!() {
		for (int i = len; ~i; --i)if (val[i])return false;
		return true;
	}
	inline void in(Bigint<len>& x) {
		char c = getchar();
		bool f = true;
		while (!isdigit(c)) {
			c = getchar();
			if (c == '-')f = false;
		}
		while (isdigit(c)) {
			x = (x << 3) + (x << 1) + Bigint<len>(c ^ 48);
			c = getchar();
		}
		x = f ? x : -x;
	}
	inline void out(Bigint<len>x) {

		Bigint<len> val[10];
		for (int i = 0; i < 10; ++i)val[i] = Bigint<len>(i);
		if (x < val[0])putchar('-'), x = -x;
		auto _10 = Bigint<len>(10);
		stack<char>s;
		while (x > _10)s.push(x.to_10_last_(_10, val)), x /= _10;
		s.push(x.to_10_last_(_10, val));
		while (s.size())putchar(s.top()), s.pop();
	}
};
int main() {

	return 0;
}
2023/12/5 21:10
加载中...