编写函数:浮点数取整(Append Code)

本文介绍了一个使用C语言编写的简单程序,该程序包含两个函数:myFloor和myCeil,用于计算传入double类型参数的Floor和Ceil值。通过输入一系列浮点数,程序将输出每个数的Floor和Ceil结果。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include <stdio.h>


int myFloor(double data)
{
    int a;
    a=(int)data;
    if(data>=0||a==data)
    return a;
    else
        return --a;

}

int myCeil(double data)
{
    int b;

    b=(int)data;

    if(data>=0&&b!=data)
    {
        b++;
        return b;
    }

   if(data<0||b==data)
    {
        return b;
    }

}




int main()
{
    double data;
    while(scanf("%lf", &data) != EOF)
        printf("%d %d\n", myFloor(data), myCeil(data));
    return 0;
}






import multiprocessing from lib import expand, cal_metrics from datetime import datetime import os, shutil, json, csv, psutil, sys from multiprocessing import Process M = 1024*1024 def addtimeline(weightmethod, weight_input): current_datetime = datetime.now() timestamp = current_datetime.strftime("%Y%m%d%H%M%S%f") new_folder_path = os.path.join('result/history/', timestamp) os.makedirs(new_folder_path) os.makedirs(new_folder_path+'/single_res') os.makedirs(new_folder_path+'/inputs') # 要复制的文件列表 file_list = ['graph_stat.json', 'weight.json', 'path_metrics.csv', 'rank.json'] for file_name in file_list: source_file = os.path.join('result/', file_name) shutil.copy2(source_file, new_folder_path+'/single_res') shutil.copytree(os.path.join('result/', 'tmp'), os.path.join(new_folder_path, 'tmp')) file_list = ['input.json', 'MainInput.json', weightmethod+'_input/'+weight_input] for file_name in file_list: source_file = os.path.join('input/', file_name) shutil.copy2(source_file, new_folder_path+'/inputs') return current_datetime def save(addnum, linknum, multi): with open('input/MainInput.json', 'r') as f: input = json.loads(f.read()) f.close() weightmethod = input['weight']; rankmethod = input['rank'] weight_input = input['weight_input'] jounal1_path = 'result/stat_all.csv'; jounal2_path = 'result/perform_log.csv' # 添加时间戳并备份 timestamp = addtimeline(weightmethod, weight_input) # stat_all.csv jounal1 = [] with open("result/graph_stat.json", 'r') as f: stat = json.loads(f.read()) f.close() hostsnum=stat["hostsnum"]; edgesnum=stat["edgesnum"]; pathsnum=stat["pathsnum"] with open("result/tmp/time.log", 'r') as f: log = f.read() f.close() ls1 = log.split() err = []; ls = []; j=0; flag=0 for i in range(len(ls1)): if flag==1: flag-=1 continue try: ls.append(float(ls1[i])) j+=1 except: if j+1 == i or j+2 == i: ls.append('None') err.append(ls1[i]) if ls1[i] == 'signal' or ls1[i] == 'code': err.append(ls1[i+1]) flag += 1 exception = ' '.join(err) print(ls) with open('result/tmp/exception.txt', 'w') as f: f.write(exception) expandtime=ls[0]; expandmem=ls[1] weighttime=ls[2]; weightmem=ls[3] metricstime=ls[4]; metricsmem=ls[5] ranktime=ls[6]; rankmem=ls[7] jounal1.append([timestamp, weightmethod, rankmethod, hostsnum, edgesnum, pathsnum, expandtime, expandmem, weighttime, weightmem, metricstime, metricsmem, ranktime, rankmem, exception]) with open(jounal1_path, 'a', newline='') as f: writer = csv.writer(f) writer.writerow(jounal1[0]) # perform_log.csv jounal2 = [] jounal2.append([timestamp, weightmethod, rankmethod, addnum, linknum, multi]) with open(jounal2_path, 'a', newline='') as f: writer = csv.writer(f) writer.writerow(jounal2[0]) def save_risk(addnum, linknum, multi): with open('input/MainInput.json', 'r') as f: input = json.loads(f.read()) f.close() weightmethod = input['weight']; rankmethod = input['rank'] weight_input = input['weight_input'] method = input["rrisk_cal"]["method"] if method=='s': riskmethod='static' elif method=='d': riskmethod='dynamic' jounal1_path = 'result/stat_all.csv'; jounal2_path = 'result/perform_log.csv' # 添加时间戳并备份 timestamp = addtimeline(weightmethod, weight_input) # stat_all.csv jounal1 = [] with open("result/graph_stat.json", 'r') as f: stat = json.loads(f.read()) f.close() hostsnum=stat["hostsnum"]; edgesnum=stat["edgesnum"]; pathsnum=stat["pathsnum"] with open("result/tmp/time.log", 'r') as f: log = f.read() f.close() ls1 = log.split() err = []; ls = []; j=0; flag=0 for i in range(len(ls1)): if flag==1: flag-=1 continue try: ls.append(float(ls1[i])) j+=1 except: if j+1 == i or j+2 == i: ls.append('None') err.append(ls1[i]) if ls1[i] == 'signal' or ls1[i] == 'code': err.append(ls1[i+1]) flag += 1 with open("result/tmp/risk_time.log", 'r') as f: log = f.read() f.close() ls2 = log.split() err = []; ls_risk = []; j=0; flag=0 for i in range(len(ls2)): if flag==1: flag-=1 continue try: ls_risk.append(float(ls2[i])) j+=1 except: if j+1 == i or j+2 == i: ls_risk.append('None') err.append(ls2[i]) if ls2[i] == 'signal' or ls2[i] == 'code': err.append(ls1[i+1]) flag += 1 for lr in ls_risk: ls.append(lr) print(lr) print(ls) exception = ' '.join(err) with open('result/tmp/exception.txt', 'w') as f: f.write(exception) expandtime=ls[0]; expandmem=ls[1] weighttime=ls[2]; weightmem=ls[3] metricstime=ls[4]; metricsmem=ls[5] ranktime=ls[6]; rankmem=ls[7] risktime=ls[8]; riskmem=ls[9] jounal1.append([timestamp, weightmethod, rankmethod,riskmethod, hostsnum, edgesnum, pathsnum, expandtime, expandmem, weighttime, weightmem, metricstime, metricsmem, ranktime, rankmem,risktime,riskmem, exception]) with open(jounal1_path, 'a', newline='') as f: writer = csv.writer(f) writer.writerow(jounal1[0]) # perform_log.csv jounal2 = [] jounal2.append([timestamp, weightmethod, rankmethod,riskmethod, addnum, linknum, multi]) with open(jounal2_path, 'a', newline='') as f: writer = csv.writer(f) writer.writerow(jounal2[0]) 解析一下函数用途与代码逻辑,不做修改优化,仅仅解释,包括传输入参数以及用途,流程,详细清晰
最新发布
08-05
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值