回 帖 发 新 帖 刷新版面

主题:那个好心的高手帮忙做一下这几条简单的程序设计题?

[em2][em3] 给些相关资料的网站连接给小女子都可以~感激不尽
死人变态老师竟然要我们做这样的题目~就要开学了~我还没做完555555[em10]


1、 运动会分数统计
任务:参加运动会有n个学校,学校编号为1……n。比赛分成m个男子项目,和w个女子项目。项目编号为男子1……m,女子m+1……m+w。不同的项目取前五名或前三名积分;取前五名的积分分别为:7、5、3、2、1,前三名的积分分别为:5、3、2;哪些取前五名或前三名由学生自己设定。(m<=20,n<=20)
功能要求:1).可以输入各个项目的前三名或前五名的成绩;
2).能统计各学校总分,
3).可以按学校编号、学校总分、男女团体总分排序输出;
4).可以按学校编号查询学校某个项目的情况;可以按项目编号查询取得前三或前五名的学校。
规定:输入数据形式和范围:20以内的整数(如果做得更好可以输入学校的名称,运动项目的名称)
输出形式:有中文提示,各学校分数为整形
界面要求:有合理的提示,每个功能可以设立菜单,根据提示,可以完成相关的功能要求。
存储结构:学生自己根据系统功能要求自己设计,但是要求运动会的相关数据要存储在数据文件中。(数据文件的数据读写方法等相关内容在c语言程序设计的书上,请自学解决)请在最后的上交资料中指明你用到的存储结构;
测试数据:要求使用1、全部合法数据;2、整体非法数据;3、局部非法数据。进行程序测试,以保证程序的稳定。测试数据及测试结果请在上交的资料中写明;


2、 一元多项式计算
任务:能够按照指数降序排列建立并输出多项式;
能够完成两个多项式的相加、相减,并将结果输入;
在上交资料中请写明:存储结构、多项式相加的基本过程的算法(可以使用程序流程图) 、源程序、测试数据和结果、算法的时间复杂度、另外可以提出算法的改进方法;


3、 猴子选大王
任务:一堆猴子都有编号,编号是1,2,3 ...m ,这群猴子(m个)按照1-m的顺序围坐一圈,从第1开始数,每数到第N个,该猴子就要离开此圈,这样依次下来,直到圈中只剩下最后一只猴子,则该猴子为大王。
要求:
输入数据:输入m,n m,n 为整数,n<m
输出形式:中文提示按照m个猴子,数n 个数的方法,输出为大王的猴子是几号 ,建立一个函数来实现此功能


4、最小生成树问题**
问题描述:若要在n个城市之间建设通信网络,只需要架设n-1条线路即可。
如何以最低的经济建设这个通信网,是一个网的最小生成树
基本要求:
(1)利用克鲁斯卡尔算法求网的最小生成树。
(2)以文本形式输出生成树中各条边以及他们的权值


5、图的建立及输出
任务:建立图的存储结构(图的类型可以是有向图、无向图、有向网、无向网,学生可以任选两种类型),能够输入图的顶点和边的信息,并存储到相应存储结构中,而后输出图的邻接矩阵。

6、拓扑排序
任务:编写函数实现图的拓扑排序。



请尽量写出每一步的算法说明~~~  

回复列表 (共25个回复)

11 楼

帮你写了一下猴子.

#include <stdio.h>
#include <conio.h>

#define MAXM    1000

int workarr[MAXM];

int Work(int m, int n)
{
    int i, j, k = 0;
     for (i=0; i<m; i++)
         workarr[i] = i+1;
    for (i=m; i>1; i--)
    {
        k = (k+n-1)%i;
        for (j=k+1; j<i; j++)
            workarr[j-1] = workarr[j];
     }
     return workarr[0];
}

int main()
{
    int m, n, res;
    printf("输入m,n (m>n): ");
    scanf("%d%d", &m, &n);
     res = Work(m, n);
    printf("按照%d个猴子,数%d个数的方法,大王的猴子是%d号\n", m, n, res);
    getch();

    return 0;
}

12 楼

高手呢?我也想知道运动会问题、一元多项式问题、图的输出这三个问题的C程序啊!
着急用呢!我们老师跟我们的题目要求这三个题目居然和楼主的一样。

13 楼

十分感谢kingwei GG,还有那位高手能帮忙做一做剩下的那些题目啊? 小女感激不尽

14 楼

帮mengxin0839写的多项式,顺便贴一下,没测过

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

typedef struct PolyNode
{
    int coef;
    int expn;
    struct PolyNode *next;
}PolyNode, *PolyType;

void FreePoly(PolyType *poly)
{
    PolyNode *p = *poly, *q;
    while (p != NULL)
    {
        q = p->next;
        free(p);
        p = q;
     }
    *poly = NULL;
}

void DispPoly(PolyType poly)
{
    PolyNode *p = poly->next;
     printf("%d", poly->expn);
     while (p != NULL)
     {
         printf(", %d, %d", p->coef, p->expn);
         p = p->next;
    }
    printf("\n");
}

void AddPoly(PolyType *res, PolyType left, PolyType right)
{
    PolyNode *t, *p = left->next, *q = right->next;
     *res = (PolyNode *)malloc(sizeof(PolyNode));
    (*res)->expn = (*res)->coef = 0;
    (*res)->next = NULL;
    t = *res;
    while (p!=NULL || q!=NULL)
    {
        if (p!=NULL && q!=NULL && p->expn==q->expn)
        {
            if (p->coef+q->coef != 0)
            {
                t->next = (PolyNode *)malloc(sizeof(PolyNode));
                t = t->next;
                t->expn = p->expn;
                t->coef = p->coef+q->coef;
                t->next = NULL;
                (*res)->expn++;
            }
            p = p->next;
            q = q->next;
        }
          else if (q==NULL || (p!=NULL && q!=NULL && p->expn>q->expn))
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = p->expn;
            t->coef = p->coef;
            t->next = NULL;
            (*res)->expn++;
            p = p->next;
            }
          else
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = q->expn;
            t->coef = q->coef;
            t->next = NULL;
            (*res)->expn++;
            q = q->next;
           }
     }
}

void SubPoly(PolyType *res, PolyType left, PolyType right)
{
    PolyNode *t, *p = left->next, *q = right->next;
     *res = (PolyNode *)malloc(sizeof(PolyNode));
    (*res)->expn = (*res)->coef = 0;
    (*res)->next = NULL;
    t = *res;
    while (p!=NULL || q!=NULL)
    {
        if (p!=NULL && q!=NULL && p->expn==q->expn)
        {
            if (p->coef-q->coef != 0)
            {
                t->next = (PolyNode *)malloc(sizeof(PolyNode));
                t = t->next;
                t->expn = p->expn;
                t->coef = p->coef-q->coef;
                t->next = NULL;
                (*res)->expn++;
            }
            p = p->next;
            q = q->next;
        }
          else if (q==NULL || (p!=NULL && q!=NULL && p->expn>q->expn))
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = p->expn;
            t->coef = p->coef;
            t->next = NULL;
            (*res)->expn++;
            p = p->next;
            }
          else
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = q->expn;
            t->coef = -q->coef;
            t->next = NULL;
            (*res)->expn++;
            q = q->next;
           }
     }
}

void ReadPoly(PolyType *poly)
{
    PolyNode *p, *q;
    int coef, expn;
    *poly = (PolyNode *)malloc(sizeof(PolyNode));
    (*poly)->expn = (*poly)->coef = 0;
    (*poly)->next = NULL;
    scanf("%d%d", &coef, &expn);
    while (expn >= 0)
    {
        p = *poly;
        q = (*poly)->next;
        while (q!=NULL && q->expn>expn)
        {
            p = p->next;
            q = q->next;
          }
          if (q!=NULL && q->expn==expn)
          {
                 if (q->coef+coef == 0)
                 {
                p->next = q->next;
                ((*poly)->expn)--;
                     free(q);
                }
                else
                    q->coef += coef;
        }
        else
        {
            p->next = (PolyNode *)malloc(sizeof(PolyNode));
            p = p->next;
            p->expn = expn;
            p->coef = coef;
            p->next = q;
            ((*poly)->expn)++;
          }
        scanf("%d%d", &coef, &expn);
     }
}

int main()
{
    PolyType left, right, res;
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    ReadPoly(&left);
     ReadPoly(&right);
     
     printf("polynomial #1: ");
     DispPoly(left);
     printf("polynomial #2: ");
     DispPoly(right);
     
     AddPoly(&res, left, right);
     printf("polynomial #1 + #2: ");
    DispPoly(res);
     FreePoly(&res);

     SubPoly(&res, left, right);
     printf("polynomial #1 - #2: ");
    DispPoly(res);
     FreePoly(&res);
     
     FreePoly(&left);
     FreePoly(&right);
     
     getch();
    return 0;
}

15 楼

输入样例
1 1
2 3
4 1
5 6
-2 3
-99 44
-1 -1

3 5
99 44
4 6
-5 6
3 4
4 6
7 7
-1 0
-1 -1

输出
polynomial #1: 3, -99, 44, 5, 6, 5, 1
polynomial #2: 6, 99, 44, 7, 7, 3, 6, 3, 5, 3, 4, -1, 0
polynomial #1 + #2: 6, 7, 7, 8, 6, 3, 5, 3, 4, 5, 1, -1, 0
polynomial #1 - #2: 7, -198, 44, -7, 7, 2, 6, -3, 5, -3, 4, 5, 1, 1, 0

16 楼

应mengxin0839的要求改成屏幕提示的了.又加了两个功能,求导和求值.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>

typedef struct PolyNode
{
    int coef;
    int expn;
    struct PolyNode *next;
}PolyNode, *PolyType;

void FreePoly(PolyType *poly)
{
    PolyNode *p = *poly, *q;
    while (p != NULL)
    {
        q = p->next;
        free(p);
        p = q;
     }
    *poly = NULL;
}

void DispPoly(PolyType poly)
{
    PolyNode *p = poly->next;
     if (p == NULL)
     {
         printf("0\n");
         return;
      }
     while (p != NULL)
     {
         if (p->expn > 0)
             printf("%+dx^%d", p->coef, p->expn);
        else
            printf("%+d", p->coef);
         p = p->next;
    }
    printf("\n");
}

void AddPoly(PolyType *res, PolyType left, PolyType right)
{
    PolyNode *t, *p = left->next, *q = right->next;
     *res = (PolyNode *)malloc(sizeof(PolyNode));
    (*res)->expn = (*res)->coef = 0;
    (*res)->next = NULL;
    t = *res;
    while (p!=NULL || q!=NULL)
    {
        if (p!=NULL && q!=NULL && p->expn==q->expn)
        {
            if (p->coef+q->coef != 0)
            {
                t->next = (PolyNode *)malloc(sizeof(PolyNode));
                t = t->next;
                t->expn = p->expn;
                t->coef = p->coef+q->coef;
                t->next = NULL;
                (*res)->expn++;
            }
            p = p->next;
            q = q->next;
        }
          else if (q==NULL || (p!=NULL && q!=NULL && p->expn>q->expn))
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = p->expn;
            t->coef = p->coef;
            t->next = NULL;
            (*res)->expn++;
            p = p->next;
            }
          else
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = q->expn;
            t->coef = q->coef;
            t->next = NULL;
            (*res)->expn++;
            q = q->next;
           }
     }
}

void SubPoly(PolyType *res, PolyType left, PolyType right)
{
    PolyNode *t, *p = left->next, *q = right->next;
     *res = (PolyNode *)malloc(sizeof(PolyNode));
    (*res)->expn = (*res)->coef = 0;
    (*res)->next = NULL;
    t = *res;
    while (p!=NULL || q!=NULL)
    {
        if (p!=NULL && q!=NULL && p->expn==q->expn)
        {
            if (p->coef-q->coef != 0)
            {
                t->next = (PolyNode *)malloc(sizeof(PolyNode));
                t = t->next;
                t->expn = p->expn;
                t->coef = p->coef-q->coef;
                t->next = NULL;
                (*res)->expn++;
            }
            p = p->next;
            q = q->next;
        }
          else if (q==NULL || (p!=NULL && q!=NULL && p->expn>q->expn))
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = p->expn;
            t->coef = p->coef;
            t->next = NULL;
            (*res)->expn++;
            p = p->next;
            }
          else
          {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->expn = q->expn;
            t->coef = -q->coef;
            t->next = NULL;
            (*res)->expn++;
            q = q->next;
           }
     }
}

void DifPoly(PolyType *res, PolyType poly)
{
    PolyNode *p = poly->next, *t;
     *res = (PolyNode *)malloc(sizeof(PolyNode));
    (*res)->expn = (*res)->coef = 0;
    (*res)->next = NULL;
    t = *res;
    while (p != NULL)
    {
        if (p->expn > 0)
        {
            t->next = (PolyNode *)malloc(sizeof(PolyNode));
            t = t->next;
            t->coef = p->coef*p->expn;
            t->expn = p->expn-1;
            t->next = NULL;
            (*res)->expn++;
          }
          p = p->next;
     }
}

long CalcPoly(PolyType poly, int x)
{
    long res = 0;
    PolyNode *p = poly->next;
    while (p != NULL)
    {
        res += p->coef*(long)pow(x, p->expn);
        p = p->next;
     }
     return res;
}

void ReadPoly(PolyType *poly)
{
    PolyNode *p, *q;
    int coef, expn;
    *poly = (PolyNode *)malloc(sizeof(PolyNode));
    (*poly)->expn = (*poly)->coef = 0;
    (*poly)->next = NULL;
    printf("input coef: ");
    scanf("%d", &coef);
    printf("input exp: ");
    scanf("%d", &expn);
    while (!(expn==0 && coef==0))
    {
        p = *poly;
        q = (*poly)->next;
        while (q!=NULL && q->expn>expn)
        {
            p = p->next;
            q = q->next;
          }
          if (q!=NULL && q->expn==expn)
          {
                 if (q->coef+coef == 0)
                 {
                p->next = q->next;
                ((*poly)->expn)--;
                     free(q);
                }
                else
                    q->coef += coef;
        }
        else if (coef != 0)
        {
            p->next = (PolyNode *)malloc(sizeof(PolyNode));
            p = p->next;
            p->expn = expn;
            p->coef = coef;
            p->next = q;
            ((*poly)->expn)++;
          }
        printf("input coef: ");
        scanf("%d", &coef);
        printf("input exp: ");
        scanf("%d", &expn);
     }
}

17 楼


void DispUsage()
{
    printf("\n1:add\n");
    printf("2:sub\n");
    printf("3:mul (NOT SUPPORTED)\n");
    printf("4:qiu_dao\n");
    printf("5:data in x\n");
    printf("6:exit\n\n");
}

int main()
{
    PolyType left, right, res;
    int op, x;
    long val;
    
    DispUsage();
     scanf("%d", &op);
     while (op != 6)
     {
         switch (op)
         {
                case 1:    printf("input the first\n"); ReadPoly(&left);
                    printf("input the second\n"); ReadPoly(&right);
                 AddPoly(&res, left, right);
                 printf("the first: "); DispPoly(left);
                 printf("the second: "); DispPoly(right);
                 printf("sum(+) is: "); DispPoly(res);
                FreePoly(&left); FreePoly(&right); FreePoly(&res);
                       break;
                case 2:    printf("input the first\n"); ReadPoly(&left);
                    printf("input the second\n"); ReadPoly(&right);
                 SubPoly(&res, left, right);
                 printf("the first: "); DispPoly(left);
                 printf("the second: "); DispPoly(right);
                 printf("sum(-) is: "); DispPoly(res);
                FreePoly(&left); FreePoly(&right); FreePoly(&res);
                    break;
            case 4: ReadPoly(&left);
                DifPoly(&res, left);
                printf("before qiudao: "); DispPoly(left);
                printf("after qiudao: "); DispPoly(res);
                FreePoly(&left); FreePoly(&res);
                break;
            case 5: ReadPoly(&left);
                printf("input x: ");
                scanf("%d", &x);
                val = CalcPoly(left, x);
                DispPoly(left);
                printf("x = %d\n", x);
                printf("sum(x) is: %ld\n", val);
                FreePoly(&left);
                break;
                default:DispUsage();
           }
         scanf("%d", &op);
      }
      
    return 0;
}

18 楼

怎么没有第5题“图的建立及输出”呢?哪位高手提供以下呀,很急!

19 楼

有第5题的程序吗?
建立图的存储结构(图的类型可以是有向图、无向图、有向网、无向网,学生可以任选两种类型),能够输入图的顶点和边的信息,并存储到相应存储结构中,而后输出图的邻接矩阵。 

谢谢~~有的发一份给我好么?
jianjin_2002@163.com

20 楼

有第5题的程序吗?
建立图的存储结构(图的类型可以是有向图、无向图、有向网、无向网,学生可以任选两种类型),能够输入图的顶点和边的信息,并存储到相应存储结构中,而后输出图的邻接矩阵。 

这样的程序么???谢谢~~有的发一份给我好么?
jianjin_2002@163.com
 

 

我来回复

您尚未登录,请登录后再回复。点此登录或注册