zoukankan      html  css  js  c++  java
  • PTA8

    这个作业属于哪个课程 C语言程序设计2
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/software-engineering-class2-2018/homework/3074
    我的课程目标 运用指针和字符函
    这个作业在哪个具体方面帮助我实现目标 运用指针和字符函数解决问题
    参考文献 C语言程序设计 P200-210

    第一题

    6-1 函数实现字符串逆序

    代码

    void f( char *p )
    {
        int i,q,h,t;
        q=0;
        while(p[i]!='')
            i++;
            h=i-1;
        while(q<=h)
        {
            t=p[q];
            p[q]=p[h];
            p[h]=t;
            q++;
            h--;
        }
        return 0;
    }
    

    思路

    问题

    第二题

    6-3 字符串的连接 (15 分)

    代码

    char *str_cat( char *s, char *t )
    {
         strcat(s,t);
         return s;
    }
    

    思路


    第三题

    7-1 输出学生成绩 (20 分)

    代码

    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
        int n,i,*p;
        double sum=0,max,min;
          scanf("%d",&n);
        if((p=(int*)malloc(sizeof(int)))==NULL){
            printf("Not able to allocate memory.
    ");
            exit(1);
        }
        for(i=0;i<n;i++)
            scanf("%d",p+i);
        max=*p; 
        min=*p;
        for(i=0;i<n;i++){
    
            if(max<*(p+i))
                max=*(p+i);
            if(min>*(p+i))
                min=*(p+i);
            sum+=*(p+i);
        }
        printf("average = %.2f
    ",sum/n);
        printf("max = %.2f
    ",max); 
        printf("min = %.2f
    ",min);
        
        free(p);
        return 0;
    
     } 
    

    思路



    问题

    我原来想直接用静态写的,但怎么都不对;
    讨论了一下法先用动态就对了;

    第四题

    7-4 字符串排序

    代码

    #include<stdio.h>
    #include<string.h>
    int main(){
    	int i,j;
    	char s[5][666],a[666];
    	for(i=0;i<5;i++)
    		scanf("%s",s[i]);
    	for(i=0;i<4;i++)
    		for(j=0;j<4-i;j++)
    			if(strcmp(s[j],s[j+1])>0){
    				strcpy(a,s[j]);
    				strcpy(s[j],s[j+1]);
    				strcpy(s[j+1],a);
    			}
    	printf("After sorted:
    ");
    	for(i=0;i<5;i++)
    		printf("%s
    ",s[i]);
    	return 0;
    }
    

    思路



    问题

    无;
    开始是开辟的空间小了;

    第五题

    7-3 计算平均成绩 (15 分)

    代码

    #include<stdio.h>
    #include<string.h>
    struct student
    {
    	char id[6];    
    	char name[11]; 
    	float score;
    };
    int main()
    {
    	struct student a[10]; 
    	int i, N;
    	float sum = 0, average;
    	scanf("%d
    ", &N);
    	for (i = 0; i < N; i++) 
    	{
    		scanf("%s%s%f", &a[i].id, &a[i].name, &a[i].score);
    		sum += a[i].score;
    	}
    	average = sum / N;
    	printf("%.2f
    ", average);
    	for (i = 0; i<N; i++) 
    	{
    		if (a[i].score < average)
    			printf("%s %s
    ", a[i].name, a[i].id);
    	}
    
    	return 0;
    }
    

    思路

    问题

    不会用动态写此题

    周/日期 这周所花时间 代码行数 学到知识点 目前比较迷惑的问题
    4/15-4/19 2day 92 指针和字符函数 动态和静态的运用

    5学习感悟

    这次的作业不是很难,通过看书和百度能学到更多的东西

    六、结对编程感想

    两个臭皮匠赛过诸葛亮

  • 相关阅读:
    RQNOJ 34 紧急援救
    Codevs 2080 特殊的质数肋骨
    POJ2975 Nim
    Bzoj1016 最小生成树计数
    POJ3613 Cow Relays
    POJ1386 Play on Words
    [从hzwer神犇那翻到的模拟赛题] 合唱队形
    HDU2824 The Euler function
    HDU1576 A/B
    HDU2669 Romantic
  • 原文地址:https://www.cnblogs.com/huangxing123/p/10737993.html
Copyright © 2011-2022 走看看