zoukankan      html  css  js  c++  java
  • 第五周编程总结

    表头:

    这个作业属于哪个课程

    C语言程序设计II

    这个作业的要求在哪里

    https://i.cnblogs.com/EditPosts.aspx?opt=1

    我在这个课程的目标是

    学习指针的定义与运用

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

    可以帮助在指针方面初步了解与学习

    参考文献

    教材,网上搜集资料

    实验题目:

    本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以是多个。

    输入格式:

    输入给出一行字符。

    输出格式:

    在一行中输出单词个数。

    输入样例:

    Let's go to room 209.
    

    输出样例:

    5

    实验代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     char a[1000];
     6     gets(a);
     7     int m, i, j;
     8     m = strlen(a);
     9     if (a[0] == ' ')
    10         j = 0;
    11     else
    12         j = 1;
    13     for (i = 0; i<m - 1; i++){
    14     if (a[i] == ' ' && a[i + 1] != ' ')
    15         j++;
    16 }
    17     printf("%d
    ", j);
    18     return 0;
    19 }

    实验思路流程图:

     

     实验结果:

    实验题目:7-1 英文单词排序 (25 分)
     

    本题要求编写程序,输入若干英文单词,对这些单词按长度从小到大排序后输出。如果长度相同,按照输入的顺序不变。

    输入格式:

    输入为若干英文单词,每行一个,以#作为输入结束标志。其中英文单词总数不超过20个,英文单词为长度小于10的仅由小写英文字母组成的字符串。

    输出格式:

    输出为排序后的结果,每个单词后面都额外输出一个空格。

    输入样例:

    blue
    red
    yellow
    green
    purple
    #
    

    输出样例:

    red blue green yellow purple 

    实验代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h> 
     4 int main (void)
     5 {
     6     FILE*fp;
     7     char  ch[20][10],a[20];
     8     int h,l,n;
     9     if((fp=fopen("D:\zhanyang.txt","a+"))==NULL){
    10         printf("File open error!
    ");
    11         exit(0); 
    12     }
    13     while(1){
    14         fscanf(fp,"%s", ch[n]);
    15         if(ch[n][0]==','){
    16             break;
    17         }
    18         n++;
    19     }
    20     for(h=0;h<n-1;h++)
    21         for(l=0;l<n-1;l++)
    22         {
    23             if(strlen(ch[l])>strlen(ch[l+1]))
    24             {
    25                 strcpy(a,ch[l]);
    26                 strcpy(ch[l],ch[l+1]);
    27                 strcpy(ch[l+1],a);
    28             }
    29         }
    30         fprintf(fp,"
    ",ch[h]);
    31         for(h=0;h<n;h++)
    32         {
    33             fprintf(fp,"%s ",ch[h]);
    34         }
    35     if(fclose(fp)){
    36         printf("Can not close the file!
    ");
    37         exit(0);
    38 }
    39 }

    实验思路:根据以前的几次写的排列法得出来的,创建文本运用指针得出。

    实验结果:

    实验进度条

    周期              花费时间             问题            代码           学到知识

    第五周               5小时                     无                68               字符串的使用

  • 相关阅读:
    stenciljs 学习四 组件装饰器
    stenciljs 学习三 组件生命周期
    stenciljs 学习二 pwa 简单应用开发
    stenciljs ionic 团队开发的方便web 组件框架
    stenciljs 学习一 web 组件开发
    使用npm init快速创建web 应用
    adnanh webhook 框架 hook rule
    adnanh webhook 框架 hook 定义
    adnanh webhook 框架request values 说明
    adnanh webhook 框架execute-command 以及参数传递处理
  • 原文地址:https://www.cnblogs.com/lll0719/p/10624102.html
Copyright © 2011-2022 走看看