qq_27965507 2015-05-30 04:48 采纳率: 0%
浏览 1533

C+语言 碰到输出手法 不能搞定 求解答 (注 : 不用迭代 )

#include "stdafx.h"
#include
using namespace std;
class Teacher
{
public:
char name[20];
Teacher * tnext;
Teacher (char * name):tnext(tnext=NULL)
{
strcpy(this->name,name);
}
void Display()
{
cout<<name;
}
};
class Course
{
public:
char name[20];
Course * next;
Teacher * thead;

Course(char * name):thead(thead=NULL),next(next=NULL)
{
    strcpy(this->name,name);
}
void Display()
{
    cout<<name;
}

};

int _tmain(int argc, _TCHAR* argv[])
{
Course * head=NULL,*before;
Teacher * te=NULL,* pre;
FILE fp=fopen("E:\VC++\heminglen\组合排序test.txt","r");
do
{
char name[20];
fscanf(fp,"%s",name);
Course * temp= new Course (name);
do
{
fscanf(fp,"%s",name);
te=new Teacher (name);
if(strncmp(te->name,"end",3)==0)break;
else
{
if(NULL == temp->thead)
temp->thead=te;
else{pre->tnext=te;}
pre=te;
}
}
while (strncmp(te->name,"end",3)!=0);
if (NULL==head)
head= temp;
else
{
before->next=temp;
}
before=temp;
}
while(!feof(fp));
/*long int a=0;
Course * k=head,*u,*v,*w;
Teacher * p,
q,*r,*s;
for(p=k->thead;p!=NULL;p=p->tnext)
for(q=k->next->thead;q!=NULL;q=q->tnext)
for(r=k->next->next->thead;r!=NULL;r=r->tnext)
for(s=k->next->next->next->thead;s!=NULL;s=s->tnext)
{
a+=1;
printf ("%ld",a);
printf("\n");
}

printf("=================================\n");*/
本意对如下原始文件
数学 赵老师 钱老师 end
语文 孙老师 李老师 end
历史 何老师 郑老师 end
化学 华老师 王老师 end
输出选课老师所有组合可能 如上有81种
现在需要输出所有的可能组合 需要通用方法 用链就是为了可扩展

  • 写回答

2条回答

  • devmiao 2015-05-30 04:55
    关注

    仔细调试下你的程序,你的程序问题太多了。

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值