2017华为软件精英挑战赛读文件和写文件源代码(C++)

在delop.cpp中

struct Init Var; void deploy_server(char * topo[MAX_EDGE_NUM], int line_num,char * filename) { initial(topo,line_num); char *topo_file=new char[60000]; char *str=new char[20]; sprintf(str,"%d\n\n",Var.connode_num); strncat(topo_file,str,4); for(int i = 0; i < Var.connode_num; i++) { sprintf(str,"%d %d %d\n",Var.con_linkID[i],i,Var.con_needband[i]); strncat(topo_file,str,10); } printf("\n\n %s", topo_file); write_result(topo_file, filename); }


在delop.h中
/*******************Graph初始化输入得到数据************************/#define MAXnetNote 1000//网络节点数量上限 #define MAXconNote 500//消费节点数量上限 #define MAXnoteLink 20//每个节点的最多链路数量 #define MAXserverPrice 5000//每个服务器的最大价格extern void initial(char *topo[MAX_EDGE_NUM], int line_num); struct Supply { int band; int band_price; }; struct Init { int netnode_num,netlink_num,connode_num,server_price; //网络节点数量,网络链路数量,消费节点数量,服务器单价 struct Supply Link_supply[MAXnetNote][MAXnetNote]; //每个链路总带宽大小,单位网络租用费 int con_linkID[MAXconNote],con_needband[MAXconNote]; //消费节点相连的网络节点,消费节点需要的带宽 }; extern struct Init Var;

在Graph.cpp中
void initial(char *topo[MAX_EDGE_NUM], int line_num) { char *line; int ch,s,t,b,c,len,conID,l,n; //char,srcID,detID,bandwidth,cost,length,consumptionID,linkID,consumption_need_band for(int i = 0,j; i < line_num; i++) { line = topo[i]; len = strlen(line); j = s = t = b = c = conID = l = n = 0; if(i == 0)//第一行为网络节点数量netnode_num,网络链路数量netlink_num,消费节点数量connode_num { while(!isdigit(ch = line[j++]) && j 2)&&(i <= Var.netlink_num + 3))//总有链路数量行,分别为链路起始点ID s,终止点ID t,链路总带宽 b,单位网络租用费c { while(!isdigit(ch = line[j++]) && j Var.netlink_num + 3)//总有消费节点数量行,分别为消费节点ID conID,相连网络节点ID l,视频带宽消耗需求 n { while(!isdigit(ch = line[j++]) && j



【2017华为软件精英挑战赛读文件和写文件源代码(C++)】


    推荐阅读