求助
  • 板块学术版
  • 楼主JRzyh
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/6/9 18:25
  • 上次更新2023/11/7 00:56:37
查看原帖
求助
242524
JRzyh楼主2020/6/9 18:25

蒟蒻写的int128,求助“!”的位置咋写

struct int128
{
    bool f;//符号 
	long long hig;
    long long low;
    bool fz(int a)
    {
    	return (a>0)?1:0;
	}
    bool operator < (int128 b)
    {
    	if(f&&b.f)
    	{
    		if(hig>b.hig) return 1;
    		if(hig<b.hig) return 0;
    		if(low>b.low) return 1;
    		if(low<b.low) return 0;
    		return 0;
		}
		if(!f&&!b.f)
    	{
    		if(hig>b.hig) return 0;
    		if(hig<b.hig) return 1;
    		if(low>b.low) return 0;
    		if(low<b.low) return 1;
    		return 0;
		}
    	return ((!f)?1:0);
	}
	bool operator == (int128 b)
    {
    	if(hig==b.hig&&low==b.low&&f==b.f) return 1;
    	else return 0;
	}
	bool operator <= (int128 b) 
	{
		return *this<b||*this==b 
	}
	bool operator > (int128 b)
	{
		return !(*this<=b)
	}
	bool operator >= (int128 b)
	{
		return *this>b||*this==b 
	}
	void operator = (long long b)
	{
		low=b%(int(1e18));
		hig=b/(int(1e18));
	}
	int128 operator - (int128 b)
	{
		if(f&&b.f||!f&&!b.f)
		{
			if(*this>=b)
			{
				int128 k;
    			k.low=0,k.hig=0;
    			k.low=low-b.low;
    			k.hig=k.low/(int(1e18))+hig-b.hig;
    			k.low%=(int(1e18));
    			k.f=f;
    			return k;
			}
			else
			{
				int128 k;
    			k.low=0,k.hig=0;
    			k.low=low-b.low;
    			k.hig=k.low/(int(1e18))+hig-b.hig;
    			k.low%=(int(1e18));
    			k.f=!f;
    			return k;
			}
		}
		else
		{
			//!!!!!!!!!
		}
	}
	int128 operator -= (int128 b)
	{
		*this=*this-b;
	}
	int128 operator + (int128 b)
	{
    	if(f&&b.f||!f&&!b.f)
    	{
    		int128 k;
    		k.low=0,k.hig=0;
    		k.low=low+b.low;
    		k.hig=k.low/(int(1e18))+hig+b.hig;
    		k.low%=(int(1e18));
    		k.f=f;
    		return k;
		}
		else
		{
			//!!!!!!!!!!!!
		}
	}
	void operator += (int128 b)
	{
		*this=*this+b;
	}
	int128 operator * (int b)
	{
    	int128 k;
    	k.low=0,k.hig=0;
    	k.low=low*b;
    	k.hig+=k.low/(int(1e18))+b*hig;
    	k.low%=(int(1e18));
    	k.f=f^fz(b);
    	k.f=!k.f;
    	return k;
	}
	void operator *= (int b)
	{
		*this=*this*b;
	}
	int128 operator * (int128 b)
	{
    	//!!!!!!
	}
	void operator *= (int128 b)
	{
		*this=*this*b;
	}
	bool operator != (int b)
	{
		return !(*this==b);
	}
	int128 operator / (int b)
	{
		//!!!!!! 
	} 
	void operator /= (int b)
	{
		*this=b/(*this);
	}
	int operator % (int b)//如果模数爆int我就把出题人掐死 
	{
		//!!!!!! 
	} 
	void operator %= (int b)
	{
		*this=b%*this;
	}
	friend istream& operator >> (istream &in,int128 a) 
	{
		std::string str;
		in>>str;
		for(int i=0;i<str.size()-16;i++)
		{
			a.hig*=10;
			a.hig+=str[i]-'0';
		}
		for(int i=str.size()-16;i<str.size();i++)
		{
			a.low*=10;
			a.low+=str[i]-'0';
		}
		return in;
	}
	friend ostream& operator << (ostream &out,int128 a) 
	{
		if(a.hig<=0) out<<a.low;
		else printf("%d%018d",a.hig,a.low);
		return out;
	}
};

另外如果其他地方有bug还请大佬指出

2020/6/9 18:25
加载中...