| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2496 人关注过本帖, 1 人收藏
标题:[求助]:《学校课程表自动编排和打印》编程
只看楼主 加入收藏
天天向上
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-6-3
收藏
得分:0 
微风 不要光说不练啦
你就把程序写出来呀
2006-06-03 19:09
天天向上
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-6-3
收藏
得分:0 
好的 我等你
2006-06-03 19:10
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
收藏
得分:0 

#include<conio.h>
#include<stdio.h>
#define N 20

int B[N],numofteacher,help[N+1]={0};;
static char T[N];
char array[N+1]={'\0'};

void Formlist(int n);
int main()
{

int i,j,k=0;
char ch=65;

printf("Please input the number of the teachers:");
do{
scanf("%d",&numofteacher);
if(numofteacher<0||numofteacher>20)
puts("Input wrong!enter again:\n");
}while(numofteacher<0||numofteacher>20);

printf("Now enter the classes number of each teacher has:");
for(i=0;i<numofteacher;i++)
{
scanf("%d",help+i);
for(j=k;j<sum(help,i+1);j++)
array[j]=ch;
k=j;
ch++;
}


Formlist(0);
getch();
return 0;
}


void Formlist(int n)
{ int i,m,j,k,c=0;

if(n==N)
{
for(m=1;m<numofteacher;m++)
{
if(m==1)
{
for(j=0;j<help[0];j++)
if(B[j]>help[0])
{
c=1;
goto out;
}
}
else
if(!c)
{
int p=sum(help,m-1),q=sum(help,m);
for(j=p;j<q;j++)
if(B[j]>q||B[j]<p)
{
c=1;
goto out;
}
}
if(0)
out:{
for(i=0;i<N+1;i++)
printf("%c",array[B[i]-1]);
printf("\n");
c=0;
getch();
}
}

}
else
{
for(k=0;k<N;k++)
{
if(!T[k])
{
B[n]=k+1;
T[k]=1;
}
else continue;
Formlist(n+1);
T[k]=0;
}
}
}
int sum(int help[],int n)
{
int i,sum=0;

for(i=0;i<n;i++)
sum+=help[i];
return sum;
}



晕死我了,我只试了一个班级,打印出全部组合,
可我调了N久,还是有问题饿.....
楼主您帮我改改吧.
我的垃圾算法:
构造一个20的全排列,每个数对应一个字母(即为学科)
打印出结果。
昨天想了一晚上,今天还是没调好,晕死我了,而且越调越不可思仪,弄得我都晕了!!
哎!


对不礼貌的女生收钱......
2006-06-04 10:49
soft_wind
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:1430
专家分:0
注 册:2006-4-5
收藏
得分:0 


5 
4 4 4 4 4 
为输入,
上面的程序还少一个"AAAABBBBCCCCDDDD"
而且程序在输出所有答案并没有进行检验是否已经和前面重复.
我原本以为问题很好解决,但调了老半天,第二个问题,老是解决不了.
大家来帮忙看一下,
下面这个是又调了的程序,
#include<conio.h>
#include<stdio.h>
#define N 20

int B[N],numofteacher,help[N+1]={0};;
static char T[N];
char array[N+1]={'\0'};
char record[N+1]={'\0'};
void Formlist(int n);
int main()
{

int i,j,k=0;
char ch=65;

printf("Please input the number of the teachers:");
do{
scanf("%d",&numofteacher);
if(numofteacher<0||numofteacher>20)
puts("Input wrong!enter again:\n");
}while(numofteacher<0||numofteacher>20);

printf("Now enter the classes number of each teacher has:");
for(i=0;i<numofteacher;i++)
{
scanf("%d",help+i);
for(j=k;j<sum(help,i+1);j++)
array[j]=ch;
k=j;
ch++;
}

for(i=0;i<N+1;i++)
record[i]=array[i];

Formlist(0);
getch();
return 0;
}


void Formlist(int n)
{ int i,m,j,k,c=0;

if(n==N)
{
for(m=1;m<numofteacher;m++)
{
if(m==1)
{
for(j=0;j<help[0];j++)
if(B[j]>help[0])
{
c=1;
goto out;
}
}
else
if(!c)
{
int p=sum(help,m-1),q=sum(help,m);
for(j=p;j<q;j++)
if(B[j]>q||B[j]<p)
{
c=1;
goto out;
}
}
if(0)
out:{
for(i=0;i<N;i++)
printf("%c",record[i]);
for(i=0;i<N+1;i++)
{
if(record[i]!=array[B[i]-1])
{
for(j=0;j<N+1;j++)
sprintf(&record[j],"%c",array[B[j]-1]);
break;
}
}
printf("\n");
c=0;
getch();
}
}

}
else
{
for(k=0;k<N;k++)
{
if(!T[k])
{
B[n]=k+1;
T[k]=1;
}
else continue;
Formlist(n+1);
T[k]=0;
}
}
}
int sum(int help[],int n)
{
int i,sum=0;

for(i=0;i<n;i++)
sum+=help[i];
return sum;
}

现在我又设定了一个record数组,用来区别和下一个数组array[B[]+1]是否完全相同,如果有不同的,则全部赋给record.但却达不到区分的效果,请大家帮忙看看,谢谢。


对不礼貌的女生收钱......
2006-06-04 11:46
西单小六
Rank: 1
等 级:新手上路
帖 子:11
专家分:1
注 册:2011-12-12
收藏
得分:0 
谢,拿来学习一下
2011-12-21 16:49
西单小六
Rank: 1
等 级:新手上路
帖 子:11
专家分:1
注 册:2011-12-12
收藏
得分:0 
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"
#include"string.h"
#define SIZE sizeof(struct student)
struct student{
    int Subject;
    struct student * next;
};
struct subject
{
    int subject;             //科目数,且规定一名教师教授一门课程
    int classroom;           
};
struct student *creatlist(int subject)
{
    struct student * head;
    struct student * p;
    struct student * p1;
    int i;
    head=(struct student *)malloc(SIZE);
    head->next=NULL;
    p1=head;
    for(i=0;i<subject;i++)
    {
        p=(struct student *)malloc(SIZE);
        p->Subject=i;
        p->next=p1->next;
        p1->next=p;
        p1=p1->next;
    }
    p1->next=NULL;
    return head;
}
void save(int a)
{
    char bb,bd;
    FILE *fp;
    if(a<=9)
    {
        bb='0'+a;
        fp=fopen("kebiao.txt","a+");
        fputc(' ',fp);
        fputc(bb,fp);
        fclose(fp);
    }
    else{
        bb='0'+a/10;
        bd='0'+a%10;
        fp=fopen("kebiao.txt","a+");
        fputc(bb,fp);
        fputc(bd,fp);
        fclose(fp);
    }
}

void save1()
{
    char a[150]="\n|                                                            班级";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(a,fp);
    fclose(fp);
}
void save2(char b)
{
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputc(b,fp);
    fclose(fp);
}
void save3()
{
    char c[150]="的课表                                                             |\n";//135
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(c,fp);
    fclose(fp);
}
void save4()
{
    char d[100]="|                         |";//27
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(d,fp);
    fclose(fp);
}
void save5(int a)
{
    char e[10]="|   教师";//27
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(e,fp);
    fclose(fp);
    save(a);
}
void save6(int a)
{
    char f[10]=" 科目";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(f,fp);
    fclose(fp);
    save(a);
}
void save7(int a)
{
    char g[10]=" 教室",gg[4]="  |";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(g,fp);
    fclose(fp);
    save(a);
    fp=fopen("kebiao.txt","a+");
    fputs(gg,fp);
    fclose(fp);
}
void save8()
{
    char h[2]="\n";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(h,fp);
    fclose(fp);
}
void save9()
{
    char i[150]="\n|          星期一         ||          星期二         ||          星期三         ||          星期四         ||          星期五         |\n";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(i,fp);
    fclose(fp);
}
void save10()
{
    char j[150]="---------------------------------------------------------------------------------------------------------------------------------------";
    FILE *fp;
    fp=fopen("kebiao.txt","a+");
    fputs(j,fp);
    fclose(fp);
}
main()
{
    int n,i,j,grade,gr,cm,m=0;
    int mm=0;
    int aa,ab;
    int bb=1;
    struct subject a[3][6][50];
    struct student *p1,*p2,*p,*mhead;
    printf("输入班级个数(1~15之间):\n");   //定义班级个数
    scanf("%d",&grade);
    printf("输入课程数目(最少为%d门课程):(0<n<=15)\n",grade);
    scanf("%d",&n);
    printf("则需要%d名教师\n",n);
   
    printf("输入教室间数(最少为%d间教室):\n",grade);
    scanf("%d",&cm);
    if((n>0)&&(n<=6))                  //将第一个班的课程表排好
    {
        for(j=0;j<2;j++)
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    a[i][j][0].subject=a[i][j+3][0].subject=m;
                }else{
                    a[i][j][0].subject=a[i][j+3][0].subject=-1;        
                }
                m++;
            }
        }
        m=0;
        for(i=0;i<3;i++)          //周三不安排课程
            a[i][2][0].subject=-1;
        for(j=0;j<2;j++)         //排 其他班级的课表
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    mhead=creatlist(n);
                    p1=mhead->next;
                    p2=mhead;
                    while(p2->next!=NULL)
                    {
                        p2=p2->next;
                    }
                    while(p1->Subject!=a[i][j][0].subject)
                    {
                        p=(struct student *)malloc(SIZE);
                        p->Subject=p1->Subject;
                        p1=p1->next;
                        p->next=p2->next;
                        p2->next=p;
                        p2=p2->next;
                        
                    }
                    p1=p1->next;
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=p1->Subject;
                        a[i][j+3][gr].subject=a[i][j][gr].subject;
                        p1=p1->next;
                    }
                }else{
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j+3][gr].subject=a[i][j][gr].subject=-1;
                    }
                }
                m++;
            }
        }
        for(gr=0;gr<grade;gr++)
        {
            save1();
            printf("班级%d的课表为:\n",gr+1);
            save(bb);
            bb=bb+1;
            save3();
            save10();
            save9();
            save10();
            save8();
            for(i=0;i<3;i++)
            {
                for(j=0;j<5;j++)
                {
                    if(j!=2)
                    {
                        if(a[i][j][gr].subject==-1)
                        {
                            printf("          ");
                            save4();
                        }else{
                            printf("t%d s%d c%d  ",a[i][j][gr].subject+1,a[i][j][gr].subject+1,gr+1);
                            aa=a[i][j][gr].subject+1;
                            ab=gr+1;
                            save5(aa);
                            save6(aa);
                            save7(ab);
                        }
                    }else{
                        printf("        ");
                        save4();
                    }
                }
                printf("\n");
                save8();
                save10();
                save8();
            }
            printf("\n");
            save8();
            save10();
        }
    }else if((n<=9)&&(n>=7))
    {
        for(j=0;j<2;j++)
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    a[i][j][0].subject=a[i][j+3][0].subject=m;
                    m++;
                }
            }
        }
        for(i=0;i<3;i++)
        {
            if(m<n)
            {
                a[i][2][0].subject=m;
            }else{
                a[i][2][0].subject=-1;
            }
            m++;
        }
        m=0;
        for(j=0;j<3;j++)         //排 其他班级的课表
        {
            for(i=0;i<3;i++)
            {
                if(m<n)
                {
                    mhead=creatlist(n);
                    p1=mhead->next;
                    p2=mhead;
                    while(p2->next!=NULL)
                    {
                        p2=p2->next;
                    }
                    while(p1->Subject!=a[i][j][0].subject)
                    {
                        p=(struct student *)malloc(SIZE);
                        p->Subject=p1->Subject;
                        p1=p1->next;
                        p->next=p2->next;
                        p2->next=p;
                        p2=p2->next;
                        
                    }
                    p1=p1->next;
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=p1->Subject;
                        a[i][j+3][gr].subject=a[i][j][gr].subject;
                        p1=p1->next;
                    }
                }else{
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j+3][gr].subject=a[i][j][gr].subject=-1;
                    }
                }
                m++;
            }
        }
        for(gr=0;gr<grade;gr++)
        {
            save1();
            printf("班级%d的课表为:\n",gr+1);
            save(bb);
            bb=bb+1;
            save3();
            save10();
            save9();
            save10();
            save8();
            for(i=0;i<3;i++)
            {
                for(j=0;j<5;j++)   
                {
                    if(a[i][j][gr].subject!=-1)
                    {
                        printf("t%d s%d c%d  ",a[i][j][gr].subject+1,a[i][j][gr].subject+1,gr+1);
                        aa=a[i][j][gr].subject+1;
                        ab=gr+1;
                        save5(aa);
                        save6(aa);
                        save7(ab);
                    }else{
                        printf("          ");
                        save4();
                    }
                }
                printf("\n");
                save8();
                save10();
                save8();
            }
            printf("\n");
            save8();
            save10();
            save8();
        }
    }else if((n<=15)&&(n>=10))
    {
        for(i=0;i<3;i++)
        {
            for(j=0;j<5;j++)
            {
                if(m<n)
                {
                    a[i][j][0].subject=m;
                }else{
                    a[i][j][0].subject=-1;
                }
                m++;
            }
        }
        m=0;
        for(i=0;i<3;i++)
        {
            for(j=0;j<5;j++)
            {
                if(m<n)
                {
                    mhead=creatlist(n);
                    p1=mhead->next;
                    p2=mhead;
                    while(p2->next!=NULL)
                    {
                        p2=p2->next;
                    }
                    while(p1->Subject!=a[i][j][0].subject)
                    {
                        p=(struct student *)malloc(SIZE);
                        p->Subject=p1->Subject;
                        p1=p1->next;
                        p->next=p2->next;
                        p2->next=p;
                        p2=p2->next;
                    }
                    
                    p1=p1->next;
                    for(gr=1;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=p1->Subject;
                        p1=p1->next;
                    }
                }else{
                    for(gr=0;gr<grade;gr++)
                    {
                        a[i][j][gr].subject=-1;
                    }
                }
                m++;
            }
        }
        for(gr=0;gr<grade;gr++)
        {
            save10();
            save1();
            printf("班级%d的课表为:\n",gr+1);
            save(bb);
            bb=bb+1;
            save3();
            save10();
            save9();
            save10();
            save8();
            for(i=0;i<3;i++)
            {
                for(j=0;j<5;j++)
                {
                    if(a[i][j][gr].subject!=-1)
                    {
                        printf("t%2d s%2d c%2d     ",a[i][j][gr].subject+1,a[i][j][gr].subject+1,gr+1);
                        aa=a[i][j][gr].subject+1;
                        ab=gr+1;
                        save5(aa);
                        save6(aa);
                        save7(ab);
                    }else{
                        printf("      ");
                        save4();
                    }
                }
                save8();
                save10();
                save8();
            }
            printf("\n");
            save8();
        }
    }
    return 0;
}
这是我们的大作业,其中将排课分成了三种情况,后来我发现第一种和第二种情况可以合并,不过着急交作业就没有弄,最后是TXT文件输出的,就是比较简单,
交流一下……


2011-12-29 19:07
快速回复:[求助]:《学校课程表自动编排和打印》编程
数据加载中...
 
   



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

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