#include <stdio.h>
#include <stdlib.h>
#include <string.h>
全部代码
int main()
{
char PATHNAME[20];
char NAME[30] = "YOURNAME_";
int V = 0;
/*gate nums*/
int E = 0;
/*wires nums*/
int j = 0;
/*第一个while计数用*/
int ft = 0;
/*标志是哪一个门在扇出*/
int gate[5000];
int iDontKnow[5000];
char *gateType[5000][20];
int D = 0;
/*
float weight[5000];*/
char *weight_char[10];
int fout = 0;
int fo[5000] = {0};
/*f【0】表示 0号门有几个扇出*/
int fi[5000] = {0};
/*记录了fin【4】【?】中?到底是几,同时刷新扇入数目*/
int C = 0;
int cc = 0;
int pin_in[5000];
int pin_out[5000];
int zz = 0;
int ww = 0;
/*---------以下用于输入输出文件名的拼接问题------*/
printf("enter file name :");
scanf("%s",PATHNAME);
strcat(NAME,PATHNAME );
strcat(NAME, ".out");
strcat(PATHNAME, ".in");
/*---------------以下读取 gate 的信息 ---------------------*/
FILE *fp, *fpw;
fp = fopen( PATHNAME , "r+" );
if( fp == NULL )
{
printf(" can not open file !!\n");
return 0;
}
fscanf(fp,"%d\n",&V);
while(j < V )
{
fscanf(fp,"%d %s %d\n", &gate[j], &gateType[j], &iDontKnow[j]);
j = j+1;
}
fscanf(fp,"%d\n",&E);
/*----------------------------以下读取wires的信息-------------------------*/
for(int l=0 ; l<E; l++)
{
fscanf(fp,"%d %s %d", &D, &weight_char, &ft);
/*weight[l] = atof();//现在weight_char已经成功将字符读取,关键在怎么将字符数组weight_char
转换成 字符常量
,这样才能用
atof()函数*/
fo[ft] = D - 1;
for(int l1=0 ; l1<D-1; l1++)
{
fscanf(fp," %d",&fout);
for(int u=0; u<V; u++)
{
if(fout == u)
{
fi[u] = fi[u] + 1;
break;
}
}
}
fscanf(fp,"\n");
}
/*--------------------以下求出 c
的值----------------------------*/
fclose(fp);
for(int p=0; p<V; p++)
{
if((fi[p]+fo[p]) > C )
{
C = fi[p] + fo[p];
}
}
/*--------输出-------------------------------------------------*/
fpw = fopen( NAME , "w" );
if( fpw == NULL )
{
printf(" can not write file !!\n");
return 0;
}
/*------------------------ 以下
输出c an c lines-----*/
fprintf(fpw,"%d\n",C);
for(int q=1; q<=C; q++)
{
cc = 0;
fprintf(fpw,"%d ",q);
for(int y=0; y<V; y++)
{
if((fi[y]+fo[y]) == q)
{
cc = cc + 1;
}
}
fprintf(fpw,"%d\n",cc);
}
/*---------------以下 输出 fin------------*/
for(int z=0; z<V; z++)
{
if(fi[z] == 0)
{
pin_in[zz] = z;
zz = zz + 1;
}
}
fprintf(fpw,"%d",zz);
for(int m=0; m<zz; m++)
{
fprintf(fpw," %d",pin_in[m]);
}
fprintf(fpw,"\n");
/*----------------以下输出 fout-------*/
for(int b=0; b<V; b++)
{
if(fo[b] == 0)
{
pin_out[ww] = b;
ww = ww + 1;
}
}
fprintf(fpw,"%d",ww);
for(int n = 0; n<ww; n++)
{
fprintf(fpw," %d",pin_out[n]);
}
fclose(fpw);
return 0;
}