前言
这些都是按照自己的习惯写的,代码风格因人而异。
板子
#include <bits/stdc++.h>
using namespace std;
#define upp(x,y,z) for(x=(y);x<=(z);++x)
#define low(x,y,z) for(x=(y);x>=(z);--x)
#define tt template<typename t0>
#define fs(x) fixed<<setprecision(x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ull unsigned long long
#define debug(x) cout<<"Line "<<__LINE__<<","<<(x)<<"."<<endl
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}}
tt inline void chkmin(t0 &x,t0 y){if(x>y){x=y;}}
const int eps=0xf;const int inf=0x7fffffff;const ll infll=0x7fffffffffffffff;const ull infull=0xffffffffffffffff;
const int N=1e6+eps;
bool memorybegin;
void code(){
//do something...
}
bool memoryend;
int main(){
#define DEBUG mofan101028
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); code();
#ifdef DEBUG
cout<<"CPU time used:"<<fs(3)<<(double)clock()/CLOCKS_PER_SEC<<"s."<<endl;
cout<<"Memory used:"<<fs(3)<<abs((&memoryend-&memorybegin)*1.0/1024.0/1024.0)<<"MB."<<endl;
#endif
return 0;
}板子随时调整。
拍子
#include <bits/stdc++.h>
#define tt template<typename t0>
tt inline void chkmax(t0 &x,t0 y){if(x<y){x=y;}} using namespace std;
int main(){
int T=10000; double st,ed,maxitime=0;
for(int i=1;i<=T;i++){
system("start D:\\random.exe");
st=clock(); system("start D:\\solution.exe");
ed=clock(); system("start D:\\correct.exe");
if(system("fc D:\\solution.out D:\\correct.out")){
cout<<"Wrong Answer in #"<< i <<", The key data has been saved in solution.in."<<endl;
return 0;
}
chkmax(maxitime,ed-st);
}
cout<<T<<" all Accepted! The maximum runtime is "<<maxitime<<"."<<endl;
return 0;
}规范
- 要尽量压行,每个代码块之间空一个空格。
例子
要尽量写成:
int a,b; cin>>a; cin>>b; cout<<a+b<<endl;而不要写成:
int a,b;
cin>>a;
cin>>b;
cout<<a+b<<endl;暂且不管板子中 那一行。
- 括号里内容比较少就不换行。
例子
如板子中的 和 。