请高人把这段代码转化成C#,小弟不胜感激
# include        <stdio.h>;
# include        <stdlib.h>;
typedef  struct  ele
{        int  vno;
        struct  ele  *link;
}        ELE;
typedef  struct  hnode
{        int  remainder;
        ELE  *head;
        Struct  hnode  *next;
}        HNODE;void  main()
{        int  n, i, box_count, box_volume, *a;
        HNODE  *box_h,  *box_t,  *j;
        ELE          *p,  *q;
        Printf(“输入箱子容积\n”);
        Scanf(“%d”,&box_volume);
        Printf(“输入物品种数\n”);
        Scanf(“%d”,&n);
        A=(int *)malloc(sizeof(int)*n);
        Printf(“请按体积从大到小顺序输入各物品的体积:”);
        For (i=0;i<n;i++)        scanf(“%d”,a+i);
        Box_h=box_t=NULL;
        Box_count=0;
        For (i=0;i<n;i++)
        {        p=(ELE *)malloc(sizeof(ELE));
                p->;vno=i;
                for (j=box_h;j!=NULL;j=j->;next)
                        if (j->;remainder>;=a[i])        break;
                if (j==NULL)
                {        j=(HNODE *)malloc(sizeof(HNODE));
                        j->;remainder=box_volume-a[i];
                        j->;head=NULL;
                        if (box_h==NULL)                box_h=box_t=j;
                        else        box_t=boix_t->;next=j;
                        j->;next=NULL;
                        box_count++;
                }
                else        j->;remainder-=a[i];
                for (q=j->;next;q!=NULL&&q->;link!=NULL;q=q->;link);
                if (q==NULL)
                {        p->;link=j->;head;
                        j->;head=p;
                }
                else
                {        p->;link=NULL;
                        q->;link=p;
                }
        }
        printf(“共使用了%d只箱子”,box_count);
        printf(“各箱子装物品情况如下:”);
        for (j=box_h,i=1;j!=NULL;j=j->;next,i++)
        {        printf(“第%2d只箱子,还剩余容积%4d,所装物品有;\n”,I,j->;remainder);
                for (p=j->;head;p!=NULL;p=p->;link)
                        printf(“%4d”,p->;vno+1);
                printf(“\n”);
        }
}

解决方案 »

  1.   


      int n, i, box_count, box_volume;
                int[] a;
                hnode box_h, box_t, j;
                ele p, q;
                Console.WriteLine("输入箱子容积");
                //string str  = Console.ReadLine();
                //Console.WriteLine("shuru:"+str);
                box_volume = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("输入物品种数");
                n = Convert.ToInt32(Console.ReadLine());
                a = new int[n];
                for (i = 0; i < n; i++)
                {
                    a[i] = Convert.ToInt32(Console.ReadLine());
                }            box_count = 0;
                for (i = 0; i < n; i++)
                {
                    p.vno = i;
                   
                }
    //下面的要研究下,等别人来了解决吧