| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2843 人关注过本帖
标题:[求助]分类情况的算法流程图怎么画?
只看楼主 加入收藏
lwb3b
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-10-11
收藏
 问题点数:0 回复次数:9 
[求助]分类情况的算法流程图怎么画?


下面是我写的关于学校举行运动会的分数统计系统中的一段关于排序分类的算法及源代码。。是有关于按总分排序,按男子团体总分排序,按女子团体总分排序的实现代码。由于本人以前没画过分类情况的流程图。。所以这里请大虾帮忙画下流程图或者给个思路都行。

void school_order(School *temp,int type) //type=0按总分,type=1按男总分,type=2按女总分,
{
School *p,*q,*small,*temp1;
temp1=new School;
temp1->next=NULL;
p=temp;
while(p)
{
small=p;
q=p->next;
while(q)
{
switch(type)
{
case 0:
if((q->boy+q->girl)<(small->girl+small->boy))
{
small=q;
}
break;
case 1:
if(q->boy<small->boy)
{
small=q;
}
break;
case 2:
if(q->girl<small->girl)
{
small=q;
}
break;
default:
cout<<"error"<<endl;
}
if(small!=p)
{
temp1->boy=p->boy;
p->boy=small->boy;
small->boy=temp1->boy;
temp1->girl=p->girl;
p->girl=small->girl;
small->girl=temp1->girl;
strcpy(temp1->name,p->name);
strcpy(p->name,small->name);
strcpy(small->name,temp1->name);
temp1->number=p->number;
p->number=small->number;
small->number=temp1->number;
}
q=q->next;
}
p=p->next;
}
}

搜索更多相关主题的帖子: 流程图 算法 总分 源代码 type 
2006-10-11 15:55
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
temp1->boy=p->boy;
p->boy=small->boy;
small->boy=temp1->boy;
temp1->girl=p->girl;
p->girl=small->girl;
small->girl=temp1->girl;
strcpy(temp1->name,p->name);
strcpy(p->name,small->name);
strcpy(small->name,temp1->name);
temp1->number=p->number;
p->number=small->number;
small->number=temp1->number;

我估计school结构体的定义如下:
struct school
{
int name[20]; //学校名称
int boy; //男生分数
int girl; //女生分数
int number; //名次
};

其实这一段无非就是将两个学校换个位置。

相当于int a=1;int b=2;
int c=a;a=b;b=c;


其他的就是一个普通循环,我呆会有空帮你改改,稍微好理解点的。

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-10-11 17:19
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
呵呵,我改好了,只是不知道你的number到底是什么?

我就不用number了。

struct School
{
char name[20]; //学校名称
int boy; //男生分数
int girl; //女生分数
School(char* na,int b,int g,int nu):boy(b),girl(g),number(nu)
{
strcpy(name,na);
}
friend ostream&operator<<(ostream&os,const School s)
{
os<<s.name<<\" \"<<s.boy<<\" \"<<s.girl;
return os;
}
};


int CompareBoy(const void* v1,const void* v2)
{
School *s1=(School*)v1;
School *s2=(School*)v2;
return s1->boy-s2->boy;
}

int CompareGirl(const void* v1,const void* v2)
{
School *s1=(School*)v1;
School *s2=(School*)v2;
return s1->girl-s2->girl;
}

int CompareAll(const void* v1,const void* v2)
{
School *s1=(School*)v1;
School *s2=(School*)v2;
return (s1->girl+s1->boy)-(s2->girl+s2->boy);
}

typedef int (*Compare)(const void* v1,const void* v2);

Compare cmp[3]={CompareBoy,CompareGirl,CompareAll};

class SportMeetScoreSys
{
public:
vector<School> m_schsScore;
public:
SportMeetScoreSys();
void Order_School(int nType);
void Display();
};

typedef SportMeetScoreSys SMSS;

SMSS::SportMeetScoreSys()
{
School s1(\"学校1\",100,200);
School s2(\"学校2\",200,100);
School s3(\"学校3\",600,400);
School s4(\"学校4\",200,300);
School s5(\"学校5\",300,500);
School s[5]={s1,s2,s3,s4,s5};
for (int i=0;i<5;i++)
{
m_schsScore.push_back(s[i]);
}
}

void SMSS::Order_School(int nType)
{
qsort(m_schsScore.begin(),m_schsScore.size(),sizeof(School),cmp[nType]);
}

void SMSS::Display()
{
for(int i=0;i<5;i++)
cout<<m_schsScore[i]<<endl;
}

int main(int argc, char* argv[])
{
SMSS smss;
for(int i=0;i<3;i++)
{
smss.Order_School(i);
smss.Display();
cout<<endl<<endl;
}
return 0;
}

只是觉得这样看起来好理解点,仅供参考。

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-10-11 18:34
lwb3b
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-10-11
收藏
得分:0 

下面是我程序的结构体:

typedef struct School //学校结构
{
char name[20]; //学校名称
int number; //学校编号
int boy; //男子团体总分
int girl; //女子团体总分
School *next;
}School;
我主要是这一段的程序流程图没什么头绪,,因为以前没用过分类的方法画流程图,所以这一部分的程序流程图画不出来。。非常渴望得到高手们的指点。。。具体这一部分的流程图怎么设计呢?

2006-10-11 18:35
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
    在论坛上画图是件极其不方便的事,所以可能是不行了,大家也没时间去弄软件画图回答你,所以只能讲究着用更清晰的代码来回答你了。

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-10-11 18:39
lwb3b
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-10-11
收藏
得分:0 

我把源程序贴出来吧。。

#include<iostream.h>
#include<iomanip.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdio.h>
#include<conio.h>

typedef struct School //学校结构
{
char name[20]; //学校名称
int number; //学校编号
int boy; //男子团体总分
int girl; //女子团体总分
School *next;
}School;

typedef struct Sport //运动项目结构
{
char name[20]; //运动项目名称
int isboy; //0为女项目,1为男项目
int is3; //0为取前五名,1为取前五名
int number; //项目编号
int first; //第一名学校编号
int second; //第二名学校编号
int third; //第三名学校编号
int fourth; //第四名学校编号
int fifth; //第五名学校编号
Sport *next;
}Sport;

int getint(int a) //字符转换成数字
{
return (int)(a-'0');
}
School * head1;
void school_add() //添加学校
{
School * p;
int mark=0;
p=new School;
cout<<"请输入学校名称:";
cin>>p->name;
char c;
while (mark!=1)
{
cout<<"请输入学校编号:";
cin>>c;
if (!isdigit(c))//是否为数字
{
cout<<"数据非法"<<endl;
}
else
{
mark=1;
p->number=c;
}
}
p->boy=0;
p->girl=0;
p->next=head1->next;
head1->next=p;
cout<<"成功添加了一个学校"<<endl;
}

int school_getlong(School *first)//得到链表长度
{
int i=0;
while (first->next!=NULL)
{
i++;
first=first->next;
}
return i;
}

void school_write()//将学校数据写入文本
{
School * p;
p=head1;
p=p->next;
ofstream outfile("School.txt",ios::out);
outfile<<school_getlong(p)+1<<" ";
while (p!=NULL)
{
outfile<<p->name<<" "<<p->number<<" "<<p->boy<<" "<<p->girl<<" ";
p=p->next;
}
outfile.close();
cout<<"Write Success!"<<endl;

}

void school_read()//从文本读入学校数据
{
int i;
ifstream infile ("School.txt",ios::in);
infile>>i;
while(i>0)
{
School * p;
p=new School;
infile>>p->name>>p->number>>p->boy>>p->girl;
p->next=head1->next;
head1->next=p;
i--;
}
cout<<"School Data Read Success!"<<endl;
}

void school_output(School *p)//输出学校
{
cout<<" 校名    编号 男团总分 女团总分 总分\t\n";
while(p)
{
cout<<p->name<<"\t"<<getint(p->number)<<"\t"<<p->boy<<"\t"<<p->girl<<"\t "<<(p->girl+p->boy)<<endl;
p=p->next;
}
}

int school_isexist(int a)//检验学校是否存在
{
int b=0;
School *p;
p=head1;
p=p->next;
while(p)
{
if(p->number==a)
{
return 1;
}
p=p->next;
}
return 0;
}

void school_show(int a)//输出所有学校
{
School *p;
p=head1;
p=p->next;
while(p)
{
if(p->number==a)
{
cout<<p->name<<" ";
return;
}
p=p->next;
}
cout<<" 无   ";
}

void school_search(int a)//按编号搜索学校
{
School *p;
p=head1;
p=p->next;
while(p)
{
if(p->number==a)
{
cout<<"校名:"<<p->name<<" "<<"男子团体总分:"<<p->boy<<" "<<"女子团体总分:"<<p->girl<<" "<<"总分:"<<(p->boy+p->girl)<<" ";
return;
}
p=p->next;
}
cout<<"无此编号";
}

void school_addmark(int a,int b,int c)//a为分数,b为学校编号,c=1表示男,c=0表示女
{
School *p;
p=head1;
p=p->next;
while(p)
{
if(p->number==b)
{
if(c=='1')
{
p->boy=p->boy+a;
}
else
{
p->girl=p->girl+a;
}
}
p=p->next;
}
}

2006-10-11 18:43
lwb3b
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-10-11
收藏
得分:0 

void school_order(School *temp,int type) //type=0按总分,type=1按男总分,type=2按女总分,
{
School *p,*q,*small,*temp1;
temp1=new School;
temp1->next=NULL;
p=temp;
while(p)
{
small=p;
q=p->next;
while(q)
{
switch(type)
{
case 0:
if((q->boy+q->girl)<(small->girl+small->boy))
{
small=q;
}
break;
case 1:
if(q->boy<small->boy)
{
small=q;
}
break;
case 2:
if(q->girl<small->girl)
{
small=q;
}
break;
default:
cout<<"error"<<endl;
}
if(small!=p)
{
temp1->boy=p->boy;
p->boy=small->boy;
small->boy=temp1->boy;
temp1->girl=p->girl;
p->girl=small->girl;
small->girl=temp1->girl;
strcpy(temp1->name,p->name);
strcpy(p->name,small->name);
strcpy(small->name,temp1->name);
temp1->number=p->number;
p->number=small->number;
small->number=temp1->number; //将学校的名字互换
}
q=q->next;
}
p=p->next;
}
}

Sport * head2;

int sport_isexist(int a) //检查运动项目(编号)是否已经存在
{
int b=0;
Sport *p;
p=head2;
p=p->next;
while(p)
{
if(p->number==a)
{
return 1;
}
p=p->next;
}
return 0;
}

void sport_add() //添加项目
{
Sport * p;
int mark=0;
p=new Sport;
cout<<"请输入项目名称:";
cin>>p->name;
char c;
while (mark!=1)
{
cout<<"请输入项目编号:";
cin>>c;
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else
{
if(sport_isexist(c))
{
cout<<"该编号已存在"<<endl;
}
else
{
mark=1;
p->number=c;
}
}
}
mark=0;
while (mark!=1)
{
cout<<"请输入项目类型(0为女子项目,1为男子项目):";
cin>>c;
p->isboy=(int)(c-'0');//字符转换成数字
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else if(p->isboy<0||p->isboy>1)
{
cout<<"数据非法"<<endl;
}
else
{
mark=1;
p->isboy=c;
}
}
mark=0;
while (mark!=1)
{
cout<<"请输入项目名次情况(0为取前3名,1为取前5名):";
cin>>c;
p->is3=(int)(c-'0');
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else if(p->is3<0||p->is3>1)
{
cout<<"数据非法"<<endl;
}
else
{
mark=1;
p->is3=c;
}
}
mark=0;
while (mark!=1)
{
cout<<"请输入第一名的学校编号:";
cin>>c;
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else
{
if(!school_isexist(c))
{
cout<<"该学校不存在,请先添加";
}
else
{
mark=1;
p->first=c;
if(p->is3=='0')
school_addmark(5,c,p->isboy);
else
school_addmark(7,c,p->isboy);
}
}
}
mark=0;
while (mark!=1)
{
cout<<"请输入第二名的学校编号:";
cin>>c;
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else
{
if(!school_isexist(c))
{
cout<<"该学校不存在,请先添加";
}
else
{
mark=1;
p->second=c;
if(p->is3=='0')
school_addmark(3,c,p->isboy);
else
school_addmark(5,c,p->isboy);
}
}
}
mark=0;
while (mark!=1)
{
cout<<"请输入第三名的学校编号:";
cin>>c;
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else
{
if(!school_isexist(c))
{
cout<<"该学校不存在,请先添加";
}
else
{
mark=1;
p->third=c;
if(p->is3=='0')
school_addmark(2,c,p->isboy);
else
school_addmark(3,c,p->isboy);
}
}
}
mark=0;
if(p->is3=='1')
{
while (mark!=1)
{
cout<<"请输入第四名的学校编号:";
cin>>c;
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else
{
if(!school_isexist(c))
{
cout<<"该学校不存在,请先添加";
}
else
{
mark=1;
p->fourth=c;
school_addmark(2,c,p->isboy);
}
}
}
mark=0;
while (mark!=1)
{
cout<<"请输入第五名的学校编号:";
cin>>c;
if (!isdigit(c))
{
cout<<"数据非法"<<endl;
}
else
{
if(!school_isexist(c))
{
cout<<"该学校不存在,请先添加"<<endl;
}
else
{
mark=1;
p->fifth=c;
school_addmark(1,c,p->isboy);
}
}
}
}
else
{
p->fourth='0';
p->fifth='0';
}
p->next=head2->next;
head2->next=p;
cout<<"成功添加了一个运动项目"<<endl;
}

int sport_getlong(Sport *first) //得到项目链表长度
{
int i=0;
while (first->next!=NULL)
{
i++;
first=first->next;
}
return i;
}

void sport_write() //将项目数据写入文本文档
{
Sport * p;
p=head2;
p=p->next;
ofstream outfile("Sport.txt",ios::out);
outfile<<sport_getlong(p)+1<<" ";
while (p!=NULL)
{
outfile<<p->name<<" "<<p->number<<" "<<p->isboy<<" "<<p->is3<<" "<<p->first<<" "<<p->second<<" "<<p->third<<" "<<p->fourth<<" "<<p->fifth<<" ";
p=p->next;
}
outfile.close();
cout<<"Write Success!"<<endl;

}

void sport_read() //从文本读取项目数据
{
int i;
ifstream infile ("Sport.txt",ios::in);
infile>>i;
while(i>0)
{
Sport * p;
p=new Sport;
infile>>p->name>>p->number>>p->isboy>>p->is3>>p->first>>p->second>>p->third>>p->fourth>>p->fifth;
p->next=head2->next;
head2->next=p;
i--;
}
cout<<"Sport Data Read Success!"<<endl;
}

void sport_output(Sport *p) //输出项目的情况
{
cout<<"   name  "<<"\t"<<"Num"<<" "<<"B/G"<<" "<<"3/5"<<"  "<<"first"<<"  "<<"second"<<"  "<<"third"<<"   "<<"fourth"<<"  "<<"fifth"<<" "<<endl;
while(p)
{
cout<<p->name<<"\t"<<" "<<getint(p->number)<<"  "<<getint(p->isboy)<<"  "<<getint(p->is3)<<" ";
school_show(p->first);
school_show(p->second);
school_show(p->third);
school_show(p->fourth);
school_show(p->fifth);
p=p->next;
}
cout<<endl;
}

void sport_search(int a) //搜索项目
{
Sport *p;
p=head2;
p=p->next;
while(p)
{
if(p->number==a)
{
cout<<"项目名:"<<p->name<<endl<<"项目类型:";
if(p->isboy==1)
{
cout<<"男子项目";
}
else
{
cout<<"女子项目";
}
cout<<endl<<"第一名:";
school_show(p->first);
cout<<endl<<"第二名:";
school_show(p->second);
cout<<endl<<"第三名:";
school_show(p->third);
cout<<endl<<"第四名:";
school_show(p->fourth);
cout<<endl<<"第五名:";
school_show(p->fifth);
return;
}
p=p->next;
}
cout<<"无此编号";
}

void main() //运动会程序主函数
{
system("color 2b"); //改变背景,前景色
head1=new School;
head1->next=NULL;
head2=new Sport;
head2->next=NULL;
//school_add();
sport_read();
school_read();
//sport_add();
School * p1;
Sport * p2;
p1=head1;
p1=p1->next;
p2=head2;
p2=p2->next;
char choose;
char temp;
//string ch=" ";
int a=1;
while(a!=0)
{
cout<<endl;
cout<<"         .oO欢迎使用运动员分数统计Oo.       "<<endl;
cout<<" **********************************************************"<<endl;
cout<<" * *"<<endl;
cout<<" * 1.输入运动项目; 2.输入学校; *"<<endl;
cout<<" * *"<<endl;
cout<<" * 3.按学校编号输出总分; 4.按总分排序; *"<<endl;
cout<<" * *"<<endl;
cout<<" * 5.按男团体总分排序; 6.按女团体总分排序; *"<<endl;
cout<<" * *"<<endl;
cout<<" * 7.按项目编号查询; 8.按学校编号查询; *"<<endl;
cout<<" * *"<<endl;
cout<<" * 0.退出 *"<<endl;
cout<<" * *"<<endl;
cout<<" * 提示:需先输入学校后才能输入运动项目 *"<<endl;
cout<<" * *"<<endl;
cout<<" **********************************************************"<<endl;
cout<<" 请选择:";
//cin>>ch;
//choose=int(ch[0])+int(ch[1])-'0'; //处理异常状态
cin>>choose;
if (!isdigit(choose))
{
system("cls");
cout<<"操作非法1"<<endl;
}
else
{
switch(getint(choose))
{
case 1:
system("cls");
cout<<"当前项目:"<<endl;
sport_output(p2);
cout<<"当前学校:"<<endl;
school_output(p1);
sport_add();
break;
case 2:
system("cls");
school_add();
break;
case 3:
system("cls");
school_output(p1);
break;
case 4:
system("cls");
school_order(p1,0);
school_output(p1);
break;
case 5:
system("cls");
school_order(p1,1);
school_output(p1);
break;
case 6:
system("cls");
school_order(p1,2);
school_output(p1);
break;
case 7:
system("cls");
cout<<"请输入项目编号:";
cin>>temp;
sport_search(temp);
break;
case 8:
system("cls");
cout<<"请输入学校编号:";
cin>>temp;
school_search(temp);
break;
case 0:
system("cls");
a=0;
break;
default:
system("cls");
cout<<"操作非法\n";
}
}
}
school_write();
sport_write();
system("exit");
}

2006-10-11 18:44
lwb3b
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-10-11
收藏
得分:0 

不是可以截图放上来看的吗??

2006-10-11 18:45
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
呵呵,你是学C的吧?

这个帖子要我转到C语言去吗?

格式都是C的

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-10-11 18:54
lwb3b
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-10-11
收藏
得分:0 
好啊,呵呵。。
2006-10-11 21:01
快速回复:[求助]分类情况的算法流程图怎么画?
数据加载中...
 
   



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

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