对拍
来源:互联网 发布:幼儿园美工室制度 编辑:程序博客网 时间:2024/05/16 18:16
有时候我们对于一个题先写了不确定的貌似是正解的程序,然后又写了保证正确的暴力。
那么我们怎样来确定我们想的正解对不对呢?对拍。
对拍我们需要这样几个文件:
data是数据生成器,right是暴力,test是待定正确程序。
举一个a+b的例子,里面是这样写的。
data.cpp
#include<iostream>#include<cstdio>#include<ctime>#include<cstdlib>using namespace std;int n;int main(){ freopen("a.in","w",stdout); srand(time(0)); n=rand()%20+2; for(int i=1;i<=n;i++) { long long a=rand()%100000; long long b=rand()%100000; cout<<a+b<<endl; } return 0;}
right.cpp
#include<iostream>#include<cstdio>using namespace std;int n;int main(){ freopen("a.in","r",stdin); freopen("right.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++) { long long a,b; scanf("%lld%lld",&a,&b); cout<<1ll*(a+b)<<endl; } return 0;}
test.cpp
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>#define LL long longusing namespace std;int a[1000],b[1000],c[1000];char s1[1001],s2[1001];int n;int main(){ freopen("a.in","r",stdin); freopen("test.out","w",stdout); scanf("%d",&n); while(n--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); scanf("%s%s",s1,s2); int l1=strlen(s1); int l2=strlen(s2); int la=1,lb=1,k=1; for(int i=1;i<=l1;i++) { if(k==10000)la++,k=1; a[la]+=k*(s1[l1-i]-'0'); k*=10; } k=1; for(int i=1;i<=l2;i++) { if(k==10000)lb++,k=1; b[lb]+=k*(s2[l2-i]-'0'); k*=10; } k=0; for(int i=1;i<=max(la,lb)+1;i++){ c[i]=a[i]+b[i]+k; if(c[i]>=10000) k=c[i]/10000; else k=0; c[i]%=10000; } int lc=max(la,lb)+1; while(c[lc]==0&&lc>1) lc--; printf("%d",c[lc]); for(int i=lc-1;i>=1;i--) printf("%04d",c[i]); puts(""); } return 0;}
把程序编译,运行.bat文件就可以了。
运行.bat文件后是这样的:
.bat文件里是这样写的:
@echo off:loop data.exe right.exe test.exefc right.out test.out if not errorlevel 1 goto looppausegoto loop
先写在.txt文件里然后把拓展名改为.bat就可以了,双击运行。
注:程序一定要编译.
阅读全文
1 0
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 对拍
- 向sdcard读写
- xml之SAX解析以及数据结构存入java对象
- js中offsetLeft/offsetTop与jq中offset().left/offset().top的区别
- HDU 6092 Rikka with Subset(动态规划 17多校第五场)
- 输入输出流
- 对拍
- IO流
- 想成为挣钱的游戏程序员要经历多少阶段?
- sd卡写入读取
- maven国内快速镜像,国内maven中央仓库地址
- c中的移位运算法
- 向SD卡写内容并且读SD内容
- [Gym-100819S] dp+离散化
- jsp内置对象及方法