| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 649 人关注过本帖
标题:自己写的C程序,运行出错,求助~~
取消只看楼主 加入收藏
scorego
Rank: 2
等 级:论坛游民
帖 子:26
专家分:20
注 册:2010-1-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
自己写的C程序,运行出错,求助~~
图片附件: 游客没有浏览图片的权限,请 登录注册
//这个由于我水平问题写的比较纠结,但又不忍心放弃~~帮忙啦
//运行后输完数据后就会出错,或者没有可能情况而又goto loop8了

/*某公司有7名保安人员:赵、钱、孙、李、周、吴、陈。
由于工作需要进行轮休制度,一星期中每人值班一天。
预先让每一个人选择自己认为合适的休息日。
请编制一程序,打印轮休的所有可能方案。
当然使每个人都满意,例如每人选择的休息日如下:
赵:星期二、星期四
钱:星期一、星期六
孙:星期三、星期日
李:星期五
周:星期一、星期四、星期六
吴:星期二、星期五
陈:星期三、星期六、星期日*/




#include <stdio.h>
  void main()      
  {
          int  zhao[7]={0},zhaoday[7]={0},qian[7]={0},qianday[7]={0},sun[7]={0},sunday[7]={0},li[7]={0},liday[7]={0},zhou[7]={0},zhouday[7]={0},wu[7]={0},wuday[7]={0},chen[7]={0},chenday[7]={0};
      int a,i,j,k,l,m,n,o,p,q;
          a=0;i=0;


loop8:          printf("\n依次输入不愿意值班日期,若输入完毕程序仍未跳转,输入0填充\n\n");

          printf("\n输入赵不想值班的日期\n:");
            for(i=0;i<=6;i++)
                    scanf("%d",&zhao);

          printf("\n输入钱不想值班的日期\n:");
             for(i=0;i<=6;i++)
                         scanf("%d",&qian);

          printf("\n输入孙不想值班的日期\n:");      
              for(i=0;i<=6;i++)
                          scanf("%d",&sun);

          printf("\n输入李不想值班的日期\n:");
              for(i=0;i<=6;i++)
                          scanf("%d",&li);

          printf("\n输入周不想值班的日期\n:");
              for(i=0;i<=6;i++)
                          scanf("%d",&zhou);

     printf("\n输入吴不想值班的日期\n:");
              for(i=0;i<=6;i++)
                          scanf("%d",&wu);

          printf("\n输入陈不想值班的日期\n:");
             for(i=0;i<=6;i++)
                         scanf("%d",&chen);


          i=1;k=0;j=0;                      //i的值代表星期几      
loop1:
          if(i<=7)
          {                                                                                          //zhao[]代表赵不想值班日期
                  for(;j<=6,zhao[j]!=i;)          //    for循环:       先让i=1,与zhao[]中的每一个数相比,当与zhao[]中所有的数不等时,把i的之赋予zhaoday[],并i++
                                       j++;                         //直到i=7                                               zhaoday[]的含义是赵可以值班的日期
                    if(j==7)                             
                             zhaoday[k]=i;
                      else
                                         {
                                                 i++;k++;
                                                         goto loop1;
                                         }
          }           


           i=1;k=0;j=0;                           
loop2:
           if(i<=7)
           {
                   for(;j<=6,qian[j]!=i;)                //同上
                                       j++;            
                   if(j==7)
                                     qianday[k]=i;
                       else
                                          {
                                                 i++;k++;
                                                          goto loop2;
                                         }
           }


           i=1;k=0;j=0;
loop3:
           if(i<=7)
           {
                   for(;j<=6,sun[j]!=i;)
                                       j++;
                      if(j==7)                       //同上
                                          sunday[k]=i;
                        else  
                                            {
                                                   i++;k++;
                                                   goto loop3;
                                           }
           }

           i=1;k=0;j=0;
loop4:
           if(i<=7)
           {
                   for(;j<=6,li[j]!=i;)
                                    j++;                   //同上
                      if(j==7)
                                          liday[k]=i;
                        else
                                             {
                                                    i++;k++;
                                                        goto loop4;
                                        }
           }


           i=1;k=0;j=0;
loop5:
          if(i<=7)
          {                                  //同上
                  for(;j<=6,zhou[j]!=i;)
                                       j++;
                    if(j==7)
                                 zhouday[k]=i;
                          else
                                                {
                                                      i++;k++;
                                                          goto loop5;
                                               }
           }

           i=1;k=0;j=0;
loop6:
           if(i<=7)                              //同上
           {
                   for(;j<=6,wu[j]!=i;)
                                   j++;
                     if(j==7)
                                         wuday[k]=i;
                         else
                                             {
                                                        i++;k++;
                                                                goto loop6;
                                           }
           }

           i=1;k=0;j=0;
loop7:
          if(i<=7)
           {
                  for(;j<=6,chen[j]!=i;)              //同上
                                      j++;
                       if(j==7)
                                            chenday[k]=i;
                          else
                                               {
                                                        i++;k++;
                                                                goto loop7;
                                               }
           }



//现在zhaoday[],sunday[]中的值是赵,孙可以值日的日期


          //用for循环全部排列可能情况并保证1~7不重复出现即可


         
          i=l=m=n=o=p=q=0;
                  
         
          for(;i<=6;i++)              //i,l,m,n,o,p,q   分别关联赵钱孙李周吴陈
           {
                          for(;l<=6;l++)
                             {
                                  for(;m<=6;m++)
                                     {for(;n<=6;n++)
                                       {
                                               for(;o<=6;o++)
                                                      {
                                                           for(;p<=6;p++)
                                                             {
                                                                       for(;q<=6;q++)   //连套for循环,排出所有的情况  全排列
                                                                           {                     //if选择出符合条件的情况(每人一天,每天不同人),把多于的情况剔除
                                                   if(zhaoday+qianday[l]+sunday[m]+liday[n]+zhouday[o]+wuday[p]+chenday[q]==28&&zhaoday*qianday[l]*sunday[m]*liday[n]*zhouday[o]*wuday[p]*chenday[q]==5040)//加法和乘法保证七个数分别是1~7
                                                                                  {  ++a;       //a累加计算总可行情况数
                                                          printf("\n赵               ");
                                                          printf("\n*****************************");
                                                      printf("\n%d ,%d ,%d ,%d ,%d ,%d ,%d  \n",zhaoday,qianday[l],sunday[m],liday[n],zhouday[o],wuday[p],chenday[q]);  
                                                                                   }                        
                                                       else      
                                                                           printf("");   
                                                                                
                                                    if(a==0)   
                                                                                  {
                                                                                         printf("\n无可能情况,请重新输入不想值班日期\n\n\n");
                                                                                         goto loop8;           //无可能情况时从头开始程序  
                                                                                  }
                                                      else  
                                                                                         printf("\n以上是所有可能的值班表,共%d种\n",a);
                                          }
                                       }
                                   }
                                }
                             }
                          }
                  }   
         
          printf("\n\n输入任意数并敲回车结束\n");
            scanf("%d",&a);         //避免程序自动结束不能看到值班表的情况


}
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 运行 
2010-03-12 23:05
scorego
Rank: 2
等 级:论坛游民
帖 子:26
专家分:20
注 册:2010-1-28
收藏
得分:0 
受教
2010-03-13 14:46
快速回复:自己写的C程序,运行出错,求助~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031868 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved