首页 > 其他分享 >读写

读写

时间:2024-08-15 15:08:18浏览次数:6  
标签:return temp BUF 读写 char true GetChar

读写

__int128

ostream& operator<<(ostream& output, lnt integer)
{
	if (integer < 0)
	{
		output << "-"; integer *= -1;
	}
	string str;
	do
	{
		str.push_back('0' + char(integer % 10)); integer /= 10;
	} while (integer != 0);
	reverse(str.begin(), str.end());
	output << str;
	return output;
}
istream& operator>>(istream& input, lnt& integer)
{
	string str; input >> str; integer = 0;
	for (int i = 0; i < str.size(); ++i)
	{
		integer = integer * 10 + str[i] - '0';
	}
	return input;
}

快读快写

namespace FastIO
{
	template<int SIZE>
	class C_IOBUF
	{
	private:
		char p[SIZE], * p1, * p2, q[SIZE], * q1, * q2;
	public:
		C_IOBUF(void) { p1 = p2 = p, q1 = q, q2 = q + SIZE; }
		char GetChar(void)
		{
			return p1 == p2 && (p2 = (p1 = p) + fread(p, 1, SIZE, stdin)), p1 == p2 ? EOF : *p1++;
		}
		void PutChar(char c)
		{
			if (q1 == q2) q2 = (q1 = q) + fwrite(q, 1, SIZE, stdout); *q1++ = c;
		}
		~C_IOBUF(void) { fwrite(q, 1, q1 - q, stdout); }
	};
	C_IOBUF<1 << 20>BUF;
	class C_IStream
	{
	private:
		bool IsChar(const char& c)
		{
			return c != ' ' && c != '\n';
		}
		bool IsDigit(const char& c)
		{
			return '0' <= c && c <= '9';
		}
	public:
		C_IStream& operator >>(int& temp)
		{
			temp = 0; char c = BUF.GetChar(); bool flag = false;
			while (IsDigit(c) != true) { if (c == '-')flag = true; c = BUF.GetChar(); }
			while (IsDigit(c) == true) { temp = temp * 10 + c - '0', c = BUF.GetChar(); }
			temp = flag ? -temp : temp; return *this;
		}
		C_IStream& operator >>(lnt& temp)
		{
			temp = 0; char c = BUF.GetChar(); bool flag = false;
			while (IsDigit(c) != true) { if (c == '-')flag = true; c = BUF.GetChar(); }
			while (IsDigit(c) == true) { temp = temp * 10 + c - '0', c = BUF.GetChar(); }
			temp = flag ? -temp : temp; return *this;
		}
		C_IStream& operator >>(char& temp)
		{
			temp = ' '; char c = BUF.GetChar();
			while (IsChar(c) != true)c = BUF.GetChar();
			temp = c; return *this;
		}
		C_IStream& operator >>(string& temp)
		{
			temp.clear(); char c = BUF.GetChar();
			while (IsChar(c) != true)c = BUF.GetChar();
			while (IsChar(c) == true)temp += c, c = BUF.GetChar();
			return *this;
		}
	}cin;
	class C_OStream
	{
	public:
		C_OStream& operator <<(int temp)
		{
			int Top = 0; static int Stack[64];
			if (temp < 0) { BUF.PutChar('-'); temp = -temp; }
			do { Stack[Top++] = temp % 10; temp /= 10; } while (temp);
			while (Top) { BUF.PutChar(Stack[--Top] + '0'); } return *this;
		}
		C_OStream& operator <<(lnt temp)
		{
			int Top = 0; static int Stack[64];
			if (temp < 0) { BUF.PutChar('-'); temp = -temp; }
			do { Stack[Top++] = temp % 10; temp /= 10; } while (temp);
			while (Top) { BUF.PutChar(Stack[--Top] + '0'); } return *this;
		}
		C_OStream& operator <<(char temp)
		{
			BUF.PutChar(temp); return *this;
		}
		C_OStream& operator <<(string temp)
		{
			for (auto c : temp)BUF.PutChar(c); return *this;
		}
		C_OStream& operator <<(const char temp[])
		{
			int p = 0; while (temp[p] != '\0')BUF.PutChar(temp[p++]); return *this;
		}
	}cout;
}

标签:return,temp,BUF,读写,char,true,GetChar
From: https://www.cnblogs.com/ProtectEMmm/p/18360924

相关文章

  • 【JUC】读写锁+邮戳锁
    文章目录关于锁的面试题简单聊聊ReentrantReadWriteLock是什么?锁的演变读写锁案例读写锁特点锁降级案例演示为什么设计锁降级(源码分析)邮戳锁StampedLock(比读写锁更快的锁)邮戳锁是什么?它是由饥饿问题引出StampedLock的特点乐观读模式Code演示传统的读写锁模式----读的......
  • Spring boot 集成 S3 进行文件读写删改
    步骤一:添加依赖首先,在SpringBoot项目中添加AWSS3相关的依赖。如果你使用Maven,可以在pom.xml中添加以下依赖:<dependency><groupId>software.amazon.awssdk</groupId><artifactId>s3</artifactId><version>2.17.27</version><!--请根据需要选择最新版本......
  • 云计算实训28——haproxy(七层代理)、python代码的读写分离
    一、haproxy----高可用、负载均衡1.安装安装ntpdate[root@haproxy~]#yum-yinstallntpdate.x86_64安装ntp[root@haproxy~]#yum-yinstallntp同步时间[root@haproxy~]#ntpdatecn.ntp.org.cn启动ntp服务[root@haproxy~]#systemctlstartntpd设置开机自......
  • 【JavaEE初阶】文件内容的读写—数据流
    ......
  • 我在高职教STM32——I2C通信之读写EEPROM(3)
            大家好,我是老耿,高职青椒一枚,一直从事单片机、嵌入式、物联网等课程的教学。对于高职的学生层次,同行应该都懂的,老师在课堂上教学几乎是没什么成就感的。正是如此,才有了借助CSDN平台寻求认同感和成就感的想法。在这里,我准备陆续把自己花了很多心思设计的教学课件......
  • python 读写excel
    概要通过pandas操作excel示例,读取sheet1,加工后写入sheet2环境:pycharm+python3.8代码示例importpandasaspdimportosdefmockdata(excelfile):ifnotos.path.exists(excelfile):print(f"{excelfile}notexists.")returndf=pd.re......
  • ceph如何进行数据的读写(2)
    本章摘要上文说到,librados/IoctxImpl.cc中调用objecter_op和objecter的op_submit函数,进行op请求的封装、加参和提交。本文详细介绍相关函数的调用。osdc中的操作初始化Op对象,提交请求设置Op对象的时间,oid,操作类型等信息。//osdc/Objector.h//mid-levelhelpersOp*pr......
  • ceph如何进行数据的读写(3)
    本章摘要上文说到,osdc中封装请求,使用message中的相关机制将请求发送出去。本文详细介绍osd服务端如何进行请求的接收。osd初始化osd启动时,定义了message变量ms_public,该变量绑定public网络,负责接收客户端的请求。ms_public会启动对应的线程进行接收,并指定接收函数。//ceph_......
  • ceph如何进行数据的读写(1)
    版本ceph版本为17.ceph如何进行读写接口的实现Ceph的客户端通过librados的接口进行集群的访问,这里的访问包括:1)对集群的整体访问2)对象的访问两类接口,这套接口(API)包括C、C++和Python的实现,接口通过网络实现对Ceph集群的访问。在客户端层面,可以在自己的程序中调用该接口,从而集......
  • 【C#】实现读写文件
    ///<summary>///同步锁///</summary>privatestaticreadonlyobjectsyncRoot=newobject();///<summary>///读同步锁///</summary>privatestaticreadonlyobjectsyncReadRoot=newobject();///<summary>///覆盖写文件......