zoukankan      html  css  js  c++  java
  • 第十二周总结

    这个作业属于哪个课程

    C语言程序设计ll

    这个作业要求在哪里

    https://edu.cnblogs.com/campus/zswxy/computer-scienceclass4-2018/homework/3236

    我在这个课程的目标是

    (1)掌握二级指针的概念,以及指针数组的应用;(2)了解指针与函数的关系,掌握指针作为函数返回值;(3)掌握单向链表的概念和操作

    这个作业在哪个具体方面帮助我实现目标

    掌握指针的应用,了解单向链表的概念

    参考文献

    C语言程序设计ll

    6-1 计算最长的字符串长度 (15 分)

    本题要求实现一个函数,用于计算有n个元素的指针数组s中最长的字符串的长度。

    函数接口定义:

    int max_len( char *s[], int n );

    其中n个字符串存储在s[]中,函数max_len应返回其中最长字符串的长度。

    裁判测试程序样例:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    #define MAXN 10
    #define MAXS 20
    
    int max_len( char *s[], int n );
    
    int main()
    {
        int i, n;
        char *string[MAXN] = {NULL};
    
        scanf("%d", &n);
        for(i = 0; i < n; i++) {
            string[i] = (char *)malloc(sizeof(char)*MAXS);
            scanf("%s", string[i]);
        }
        printf("%d
    ", max_len(string, n));
    
        return 0;
    }
    
    /* 你的代码将被嵌在这里 */

    输入样例

    4
    blue
    yellow
    red
    green

    输出样例:

    6

    代码

    int max_len( char *s[10], int n ) 
    {
    int i,max,j; 
    max=0;
    for(i=0;i<n;i++) 
    {
    j=strlen(s[i]); 
    if(j>max)
    {
    max=j;
    }
    }
    return max; 
    }

    思路图

    错误截图

    结果截图

    6-2 统计专业人数 (15 分)

    本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下:

    struct ListNode {

        char code[8];

        struct ListNode *next;

    };

    这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业的编号为02。

    函数接口定义:

    int countcs( struct ListNode *head );

    其中head是用户传入的学生学号链表的头指针;函数countcs统计并返回head链表中专业为计算机的学生人数。

    裁判测试程序样例:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    struct ListNode {
        char code[8];
        struct ListNode *next;
    };
    
    struct ListNode *createlist(); /*裁判实现,细节不表*/
    int countcs( struct ListNode *head );
    
    int main()
    {
        struct ListNode  *head;
    
        head = createlist();
        printf("%d
    ", countcs(head));
        
        return 0;
    }
    
    /* 你的代码将被嵌在这里 */

    输入样例:

    1021202
    2022310
    8102134
    1030912
    3110203
    4021205
    #

    输出样例:

    3 

    代码

    int countcs(struct ListNode*head) 
    { 
    int n=0; 
    struct ListNode *p=head; 
    while(p!=NULL)
    { if (p->code[1]=='0'&&p->code[2]=='2'){ 
    n++;
     } 
    p=p->next;
     } 
    return n; 
    }

    思路图

    错误截图

     

    结果截图

    6-3 删除单链表偶数节点 (20 分)

    本题要求实现两个函数,分别将读入的数据存储为单链表、将链表中偶数值的结点删除。链表结点定义如下:

    struct ListNode {

        int data;

        struct ListNode *next;

    };

    函数接口定义:

    struct ListNode *createlist();
    struct ListNode *deleteeven( struct ListNode *head );
    函数createlist从标准输入读入一系列正整数,按照读入顺序建立单链表。当读到−1时表示输入结束,函数应返回指向单链表头结点的指针。
    函数deleteeven将单链表head中偶数值的结点删除,返回结果链表的头指针。

    裁判测试程序样例:

    #include <stdio.h>
    #include <stdlib.h>
    
    struct ListNode {
        int data;
        struct ListNode *next;
    };
    
    struct ListNode *createlist();
    struct ListNode *deleteeven( struct ListNode *head );
    void printlist( struct ListNode *head )
    {
         struct ListNode *p = head;
         while (p) {
               printf("%d ", p->data);
               p = p->next;
         }
         printf("
    ");
    }
    
    int main()
    {
        struct ListNode *head;
    
        head = createlist();
        head = deleteeven(head);
        printlist(head);
    
        return 0;
    }
    
    /* 你的代码将被嵌在这里 */

    输入样例

    1 2 2 3 4 5 6 7 -1

    输出样例:

    1 3 5 7

    代码

    struct ListNode *createlist() 
    {
    int x;
    struct ListNode *head,*tail,*p;
    head=(struct ListNode*)malloc(sizeof(struct ListNode));
    head->next=NULL;
    tail=head;
    while(1)
    {
    p=(struct ListNode*)malloc(sizeof(struct ListNode));
    p->next=NULL;
    scanf("%d",&x);
    if(x==-1)
    break;
    p->data=x;
    p->next=NULL;
    tail->next=p;
    tail=p;
    }
    return head;
    }
    struct ListNode *deleteeven( struct ListNode *head )
    {
    struct ListNode *p,*p2;
    int flag;
    p=head;
    p2=p->next;
    while(p->next)
    {
    flag=0;
    if(p2->data%2==0)
    {
    p->next=p2->next;
    p2=p2->next;
    flag=1;
    }
    if(flag==0)
    {
    p=p->next;
    p2=p->next;
    }
    }
    return head->next;
    }

    思路图

    错误截图

    结果截图

     

     

     

    7-1 ***八皇后问题 (20 分)

    在国际象棋中,皇后是最厉害的棋子,可以横走、直走,还可以斜走。棋手马克斯·贝瑟尔 1848 年提出著名的八皇后问题:即在 8 × 8 的棋盘上摆放八个皇后,使其不能互相攻击 —— 即任意两个皇后都不能处于同一行、同一列或同一条斜线上。

    现在我们把棋盘扩展到 n × n 的棋盘上摆放 n 个皇后,请问该怎么摆?请编写程序,输入正整数 n,输出全部摆法(棋盘格子空白处显示句点“.”,皇后处显示字母“Q”,每两格之间空一格)。

    输入格式

    正整数 n (0 < n ≤ 12)

    输出格式

    若问题有解,则输出全部摆法(两种摆法之间空一行),否则输出 None。

    要求:试探的顺序逐行从左往右的顺序进行,请参看输出样例2。

    输入样例1

    3

    输出样例1

    None

    输入样例2

    6

    输出样例2

    .

    . Q . . . .
    . . . Q . .
    . . . . . Q
    Q . . . . .
    . . Q . . .
    . . . . Q .
    
    . . Q . . .
    . . . . . Q
    . Q . . . .
    . . . . Q .
    Q . . . . .
    . . . Q . .
    
    . . . Q . .
    Q . . . . .
    . . . . Q .
    . Q . . . .
    . . . . . Q
    . . Q . . .
    
    . . . . Q .
    . . Q . . .
    Q . . . . .
    . . . . . Q
    . . . Q . .
    . Q . . . .

    代码

    还是没有什么思路。。。。

     

     

    预习作业

    开发的项目的名称涉外大王蛇

    目标程序基本的实现贪吃蛇功能

    项目主体功能的描述一条通过吃豆豆来增加自身长度的蛇的一个小游戏

    现阶段已做的准备工作在网上查找相关资料,争取制作属于自己的小游戏

    小组成员名单李佳佳(组长) 宋逸豪 曹铮

    进度安排先两周查好相关资料,并熟悉相关代码,理解代码意思,中间两周,一起讨论代码进程,进行试编程,后面就制作小游戏,并不断改进更新,加入更多自己的元素

     

    学习进度条

    时间

    代码行数

    这周所花的时间

    学到的知识点简介

    3/2-3/19

    35

    四小时左右

    通过代码读取文件里的数据,并且打印

    3/9-3/19

    65

    三十分钟

     

    3/19-3/22

    186

    五个小时左右

    二维数组的用法加上二分法找元素

    3/22-3/28

    31

    三小时左右

    字符串的使用

    4/2-4/9

    130

    2小时左右

    指针的使用

    4/15-4/19

    200

    2

    指针内存的动态分配,不是很清楚使用动态分配

    4/22-4/27

    150

    3小时

    对结构体的使用熟悉

    5/6-5/9

    180

    2小时

    递归函数运行过程

    5/13-5/17

    200

    3小时

    掌握二级指针的概念,以及指针数组的应用

     

    折线图

    学习感悟:学的越来越难的,需要继续加油!

  • 相关阅读:
    ASP.NET中存取图片到数据库的示例(C#)
    解决:通过asp.net 调用FlashPrinter.exe把所有可打印的文件转换成swf文件
    vs命令提示,类生成.dll文件 .snk文件
    asp.net 为指定的图片生成缩图
    asp.net自定义错误处理页面的几种方法。
    ACCESS高效分页
    C# 读取excel数据的两个方法
    ucenter asp.net接口源码,有用户中心、站内短信接口
    存储过程中的top+变量
    测试
  • 原文地址:https://www.cnblogs.com/LUMO/p/10878577.html
Copyright © 2011-2022 走看看