当前位置: 首页 > news >正文

湿货 - 231206 - 关于如何构造输入输出数据并读写至文件中

  • TAG - 造数据、读写文件 造数据、读写文件 造数据、读写文件
  • //
  • *.in
//
#include<bits/stdc++.h>
using namespace std;/* *********** *********** 全局 ********** *********** */
string Pre_File_Name;
ofstream IN_cout;
int idx;void Modify_ABS_Path( string& path );
void F_IN_cout( const string& File_Name );
void Close_IN_cout();/* *********** *********** solve ********** *********** */
#define int long longconst int minn[]={ 0,10,10,10,10,10,10,10000,10000,10000,10000 };
const int maxx[]={ 0,10,100,100,1000,1000,10000,1000000,1000000000,10000000000,100000000000000 };//    1   2   3    3    3     4      6           9           10              14
vector<int> v;int Get_One_Data( int a,int b )
{random_device rd;   mt19937 eng(rd());uniform_int_distribution<int> dist( a,b );return dist(eng);
}void solve()
{v.resize(4);for( int i=0;i<4;i++ )v[i]=Get_One_Data( minn[idx],maxx[idx] );random_device rd;mt19937 eng(rd());shuffle( v.begin(),v.end(),eng );for( int i=0;i<4;i++ ) IN_cout<<v[i]<<" ";
}/* *********** *********** to_in ********** *********** */
signed main()
{cin>>Pre_File_Name;Modify_ABS_Path(Pre_File_Name);for( int i=1;i<=10;i++ ){idx=i; string in = Pre_File_Name + "\\\\" + to_string(idx) + ".in";F_IN_cout(in);// cout<<in<<endl;solve();Close_IN_cout();}return 0;
}/* *********** *********** 自定义函数 ********** *********** */// 修正绝对路径
void Modify_ABS_Path( string& path )
{string t_path;for( int i=0;i<path.size();i++ ) {t_path+=path[i];if( path[i]=='\\' ) t_path+='\\';}path=t_path;
}// 写入 .in 文件
void F_IN_cout( const string& File_Name )
{IN_cout.open( File_Name );if( !IN_cout.is_open() ) { cerr<<"NO_IN_cout_"<<idx<<endl; return ; }cout<<"YES_IN_cout_"<<idx<<endl;
}// 关闭 .in 文件
void Close_IN_cout()
{IN_cout.close(); cout<<"YES_Close_IN_cout_"<<idx<<endl;
}
  • *.out
//
#include<bits/stdc++.h>
using namespace std;/* *********** *********** 全局 ********** *********** */
string Pre_File_Name;
ifstream IN_cin;
ofstream OUT_cout;
int idx;void Modify_ABS_Path( string& path );
void F_IN_cin( const string& File_Name );
void F_OUT_cout( const string& File_Name );
void Close_IO();/* *********** *********** solve ********** *********** */
#define int long longint f( int n )
{int maxx=0;while( n ){maxx=max( maxx,n%10 );n/=10;}return maxx;
}void solve()
{int a,b,c,d;IN_cin>>a>>b>>c>>d;if( a>b ) swap( a,b );if( c>d ) swap( c,d );if( b-a>=10 || d-c>=10 ) { OUT_cout<<"YES"<<endl; return ; }int maxx=0;for( int i=a;i<=b;i++ )for( int j=c;j<=d;j++ )maxx=max( maxx,f( i+j ) );OUT_cout<<(maxx==9 ? "YES" : "NO")<<endl;
}/* *********** *********** to_out ********** *********** */
signed main()
{cin>>Pre_File_Name;Modify_ABS_Path(Pre_File_Name);for( int i=1;i<=10;i++ ){idx=i; string in = Pre_File_Name + "\\" + to_string(idx) + ".in";string out = Pre_File_Name + "\\" + to_string(idx) + ".out";F_IN_cin(in); F_OUT_cout(out);solve();Close_IO();}return 0;
}/* *********** *********** 自定义函数 ********** *********** */// 修正绝对路径
void Modify_ABS_Path( string& path )
{string t_path;for( int i=0;i<path.size();i++ ) {t_path+=path[i];if( path[i]=='\\' ) t_path+='\\';}path=t_path;
}// .in 文件读取
void F_IN_cin( const string& File_Name )
{IN_cin.open( File_Name );if( !IN_cin.is_open() ) { cerr<<"NO_IN_cin_"<<idx<<endl; return ; }cout<<"YES_IN_cin_"<<idx<<endl;
}// .out 文件写入
void F_OUT_cout( const string& File_Name )
{OUT_cout.open( File_Name );if( !OUT_cout.is_open() ) { cerr<<"NO_OUT_cout_"<<idx<<endl; return ; }cout<<"YES_OUT_cout_"<<idx<<endl;
}// 关闭 .in 和 .out 文件
void Close_IO()
{IN_cin.close(); OUT_cout.close(); cout<<"YES_Close_IO_"<<idx<<endl;
}

实现细节

  • 输入 .in 文件所在位置的上一级文件夹即可

参考示意图


参考链接

  • fstream —文件读写操作
  • cout与cerr区别
  • 随机数详解(mt19937 , distribution)
  • //
  • C++文件操作之freopen

作者 | 乐意奥AI

http://www.lryc.cn/news/254033.html

相关文章:

  • EasyMicrobiome-易扩增子、易宏基因组等分析流程依赖常用软件、脚本文件和数据库注释文件
  • 【Python百宝箱】漫游Python数据可视化宇宙:pyspark、dash、streamlit、matplotlib、seaborn全景式导览
  • 企业数字档案馆室建设指南
  • JavaScript中处理时间差
  • Multidimensional Scaling(MDS多维缩放)算法及其应用
  • 单片机_RTOS_架构
  • Golang rsa 验证
  • 网络安全威胁——跨站脚本攻击
  • Java利用UDP实现简单的双人聊天
  • HBase整合Phoenix
  • C# 委托/事件/lambda
  • 13款趣味性不错(炫酷)的前端动画特效及源码(预览获取)分享(附源码)
  • C# 友元程序集
  • CRM系统的数据分析和报表功能对企业重要吗?
  • 【单体架构事务失效解决方式之___代理对象加锁】
  • 面试被问到 HTTP和HTTPS的区别有哪些?你该如何回答~
  • 点评项目——短信登陆模块
  • 2023亚太地区五岳杯量子计算挑战赛
  • Python 模块的使用方法
  • 【知识】稀疏矩阵是否比密集矩阵更高效?
  • 代码随想Day24 | 回溯法模板、77. 组合
  • 搜索与回溯算法②
  • Centos图形化界面封装OpenStack Ubuntu镜像
  • 使用Jmeter进行http接口测试怎么做?
  • 创建腾讯云存储桶---上传图片--使用cos-sdk完成上传
  • 12.3_黑马MybatisPlus笔记(上)
  • 智能优化算法应用:基于寄生捕食算法无线传感器网络(WSN)覆盖优化 - 附代码
  • 全息图着色器插件:Hologram Shaders Pro for URP, HDRP Built-in
  • Python Opencv实践 - 简单的AR项目
  • Java不可变集合