湿货 - 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