文件操作(OJ数据生成)
来源:互联网 发布:网络照片素材 编辑:程序博客网 时间:2024/05/01 04:26
直接贴模板:(仅是一个例题)
第一种:
#include<cstdio>#include <iostream>#include <cmath>#include<ctime>#include<cstdlib>using namespace std;int main(){ double n, p, k, tt; FILE *fp1, *fp2; if((fp1 = fopen("Problem1_in.txt","w")) == NULL) { printf("Error.\n"); exit(0); } srand((int)time(NULL)); for(int j = 0 ; j < 1700 ; j++ ) { n = rand()%200+1; tt = rand()%1000000000+1; p = pow(tt,n); fprintf(fp1,"%.0lf %.0lf\n",n,p); } fclose(fp1); if((fp1=fopen("Problem1_in.txt","r"))==NULL) { printf("error.\n"); exit(0); } if((fp2=fopen("Problem1_out.txt","w"))==NULL) { printf("error.\n"); exit(0); } while(fscanf(fp1,"%lf%lf",&n,&p) == 2) { k = pow(p,1/n); fprintf(fp2,"%.0lf\n",k); } fclose(fp1); fclose(fp2); return 0;}
第二种:
先在编译器上运行
#include <cstdio>#include <ctime>#include <cmath>#include <cstdlib>#define IN freopen("Problem1input.txt", "r", stdin)#define OUT freopen("Problem1output.txt", "w", stdout)#define OUT1 freopen("Problem1input.txt", "w", stdout)int main(){ OUT1;double n, p, k, tt; srand((int)time(0)); for(int i = 0; i < 1700; i++) { n = rand()%200+1; tt = rand()%1000000000+1; p = pow(tt,n); printf("%.0lf %.0lf\n",n,p); } return 0;}
然后再运行
#include <cstdio>#include <ctime>#include <cmath>#include <cstdlib>#define IN freopen("Problem1input.txt", "r", stdin)#define OUT freopen("Problem1output.txt", "w", stdout)#define OUT1 freopen("Problem1input.txt", "w", stdout)int main(){IN;OUT;double n, p, k;while(~scanf("%lf%lf",&n,&p)){k = pow(p,1/n);printf("%.0lf\n",k);}return 0;}
3 0
- 文件操作(OJ数据生成)
- OJ的文件流操作
- C语言程序设计实践(OJ)-全局变量、文件操作
- 第十三周OJ(2)文件操作1
- oj 2972 文件操作1(from 千千)
- 打开文件,写入数据(文件操作)
- pickle库起到序列化操作的作用(生成cache文件)----Python数据读取加速技巧
- 第13周OJ实践 文件操作
- Jarvis oj 文件数据修复 writeup
- jsp 文件数据操作
- python文件数据操作
- 文件操作-数据统计
- Core Data 自动生成及基本数据操作(1)
- Core Data 自动生成及基本数据操作(2)
- Core Data 自动生成及基本数据操作(3)
- Core Data 自动生成及基本数据操作(1)
- Core Data 自动生成及基本数据操作(2)
- Core Data 自动生成及基本数据操作(3)
- 浅谈Redis数据库的键值设计
- HDU 1702 ACboy needs your help again!(栈与队列的基本使用)
- 7 纹理映射
- 2014Dedecms标签新增中...
- dfs
- 文件操作(OJ数据生成)
- 贪心 删数问题
- HDU 1016 Prime Ring Problem(经典DFS )
- linux进程与线程的区别
- codeforces div2 round#230 D
- iOS安全攻防(十九):基于脚本实现动态库注入
- 这辈子
- 眺望
- pn结工作原理