生成acm测试数据

data.cpp
//测试数据生成程序  10498 手动修改去掉一些前导零  
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
void data(){
    int x,y;//x,y输入 ,控制数据的范围 
    x=rand()%100;
    y=rand()%1000+1; 
    printf("%d %d\n",x,y);
}
void name(int k){ //起名字生成.in 
    char str[111];
    sprintf(str,"%d",k);
    strcat(str,".in");
    freopen(str,"w",stdout);
}
int main(){
    srand(time(NULL));
    for(int k=1;k<=10;k++){
        name(k);//起名字 
        data();// 
    }
} 
go.cpp

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double calculate(double x,double n)
{
    if(n==1)//判断是否到达递归边界n=1
        return x/(1+x);
    else//否则继续递归
        return x/(n+calculate(x,n-1));
}
int main()
{

    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
    double n,x;
    double result;
    cin>>x>>n;
    result=calculate(x,n);
    printf("%.2lf\n",result);
    return 0;

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值