| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 649 人关注过本帖
标题:自己写的C程序,运行出错,求助~~
只看楼主 加入收藏
scorego
Rank: 2
等 级:论坛游民
帖 子:26
专家分:20
注 册:2010-1-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:9 
自己写的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
lansong
Rank: 4
等 级:业余侠客
帖 子:79
专家分:226
注 册:2009-6-11
收藏
得分:0 
wa,看了就恶心
2010-03-13 09:26
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:5 
建议用枚举函数 enum定义 星期 这样更简单些
2010-03-13 09:43
zhuyunshen
Rank: 6Rank: 6
等 级:侠之大者
威 望:2
帖 子:212
专家分:455
注 册:2009-11-22
收藏
得分:0 
好难看哦
2010-03-13 09:53
陈大师
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:231
专家分:1038
注 册:2009-11-4
收藏
得分:0 
真的是好难看呀~~~~~
2010-03-13 10:12
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:5 
#include "stdafx.h"
#include "string.h"
struct workmen
{
    char name[20];
    int num;
};

void work(int x)
{
    enum weekday{mon,tue,wed,thu,fri,sat,sun};
    enum weekday week_end;
    switch(week_end=(enum weekday)x)
    {
    case mon:
        printf("his work_end is mon\n");
        break;
    case tue:
        printf("his work_end is tue\n");
        break;
    case wed:
        printf("his work_end is wed\n");
        break;
    case thu:
        printf("his work_end is thu\n");
        break;
    case fri:
        printf("his work_end is fri\n");
        break;
    case sat:
        printf("his work_end is satn");
        break;
    case sun:
        printf("his work_end is sun\n");
        break;
    default:
        break;
    }
}
void trues(int x)
{
    int y;
    if(x>=0&&x<=6)
        return ;
    else
    {    printf("Input number 0-6:");
        scanf("%d",&y);
        trues(y);
    }
}
void main()
{
    int a[7],n;
    struct workmen wor[7];
    int j,k;
    printf("Intput name:");
    scanf("%s",&wor[0].name);
    printf("\nIntput week_end:");
    scanf("%d",&wor[0].num);
    trues(wor[0].num);
    work(wor[0].num);
    a[0]=wor[0].num;
    for(j=1;j<7;j++)
    {
        printf("Intput name:");
        scanf("%s",&wor[j].name);
        printf("\nIntput week_end:");
loop:
        scanf("%d",&wor[j].num);
        trues(wor[j].num);
        for(k=0;k<j;k++)
        {
            if(a[k]==wor[j].num){n=0;break;}
            else
            {n=1;a[j]=wor[j].num;}
        }
        if(n)
            work(wor[j].num);
        else
        {
            printf("%d already be used,please change athers weekday\n",wor[j].num);
            goto loop;
        }


    }

}


随便写的 自己拿去调试吧
2010-03-13 11:21
csj_65
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:63
专家分:163
注 册:2010-3-12
收藏
得分:10 
图片附件: 游客没有浏览图片的权限,请 登录注册


代码:
#include <stdio.h>
void main()
{
int  zhao[7],qian[7],sun[7],li[7],zhou[7],wu[7],chen[7];
int i,l,m,n,o,p,q;
for(i=0;i<=6;i++)
zhao[i]=qian[i]=sun[i]=li[i]=zhou[i]=wu[i]=chen[i]=0;
printf("\n依次输入不愿意值班日期,若输入完毕程序仍未跳转,输入0填充\n\n");
printf("\n输入赵想值班的日期\n:");
for(i=0;i<=6;i++)
{
 scanf("%d",&zhao[i]);
 if(zhao[i]==0) break;
}
printf("\n输入钱想值班的日期\n:");
for(i=0;i<=6;i++)
{
scanf("%d",&qian[i]);
if(qian[i]==0) break;
}
printf("\n输入孙想值班的日期\n:");
for(i=0;i<=6;i++)
{
scanf("%d",&sun[i]);
if(sun[i]==0) break;
}
printf("\n输入李想值班的日期\n:");
for(i=0;i<=6;i++)
{
scanf("%d",&li[i]);
if(li[i]==0) break;
}
printf("\n输入周想值班的日期\n:");
for(i=0;i<=6;i++)
{
scanf("%d",&zhou[i]);
if(zhou[i]==0) break;
}
printf("\n输入吴想值班的日期\n:");
for(i=0;i<=6;i++)
{
scanf("%d",&wu[i]);
if(wu[i]==0) break;
}
printf("\n输入赵想值班的日期\n:");
for(i=0;i<=6;i++)
{
scanf("%d",&chen[i]);  
if(chen[i]==0) break;
}
for(i=0;i<=6;i++)              //i,l,m,n,o,p,q   分别关联赵钱孙李周吴陈
    for(l=0;l<=6;l++)         
        for(m=0;m<=6;m++)   
             for(n=0;n<=6;n++)                 
                 for(o=0;o<=6;o++)                     
                       for(p=0;p<=6;p++)                     
                         for(q=0;q<=6;q++)
                         {
                          if(zhao[i]+qian[l]+sun[m]+li[n]+zhou[o]+wu[p]+chen[q]==28&&zhao[i]*qian[l]*sun[m]*li[n]*zhou[o]*wu[p]*chen[q]==5040)
                          {printf("\n赵               ");
                          printf("\n*****************************");
                          printf("\n%d ,%d ,%d ,%d ,%d ,%d ,%d  \n",zhao[i],qian[l],sun[m],li[n],zhou[o],wu[p],chen[q]);  
                          }
                         }
                                                           
                                                            
                                                                       

}
仔细检查一下你的语句中有好几处语法错误,特别是数组名,最好别用goto语句,多用for和while,由于没时间我弄的简单了一点,这个需要输入的是一个星期中可以值班的时间,没有转化,结束时输入0加回车就行了。你可以参考一下。
2010-03-13 11:29
csj_65
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:63
专家分:163
注 册:2010-3-12
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2010-03-13 11:31
guoqin2010
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-3-10
收藏
得分:0 
怎么那么
2010-03-13 11:43
scorego
Rank: 2
等 级:论坛游民
帖 子:26
专家分:20
注 册:2010-1-28
收藏
得分:0 
受教
2010-03-13 14:46
快速回复:自己写的C程序,运行出错,求助~~
数据加载中...
 
   



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

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