十二周+
| 這個作業要求在哪里 | https://edu.cnblogs.com/campus/zswxy/software-engineering-class2-2018/homework/3234 |
| 我在這個課程的目標是 | 掌握指針與函數 |
| 這個作業在哪個具體方面幫助我實現目標 | 指針函數的掌握 |
| 參考文獻 | 很多大佬代碼 |
基礎作業
計算最長的字符串長度
函數接口定義: 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 20int 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\n", max_len(string, n));return 0; }/* 你的代碼將被嵌在這里 */ 輸入樣例: 4 blue yellow red green 輸出樣例: 6代碼:
int max_len( char *s[], int n ) {int m=0;for(int i=0;i<n;i++){int t=strlen(s[i]);if(m < t){m=t;}}return m; }流程圖:
運行中遇到的問題:
無
統計專業人數
本題要求實現一個函數,統計學生學號鏈表中專業為計算機的學生人數。鏈表結點定義如下:
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\n", countcs(head));return 0; }/* 你的代碼將被嵌在這里 */ 輸入樣例: 1021202 2022310 8102134 1030912 3110203 4021205 # 輸出樣例: 3代碼:
int countcs( struct ListNode *head ) {int num = 0;struct ListNode *p = head;while(p != NULL){if(p->code[1] == '0' && p->code[2] == '2')num++;p = p->next;}return num; }流程圖
運行中遇到的問題:
一些簡單的編譯錯誤
刪除單鏈表偶數節點
代碼:
struct ListNode *createlist() { int data;struct ListNode *head,*p,*tail;int size=sizeof(struct ListNode);head=p=NULL;scanf("%d",&data);while(data!=-1){p=(struct ListNode*)malloc(size);p->data=data;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;scanf("%d",&data);} return head;} struct ListNode *deleteeven( struct ListNode *head ) {struct ListNode *p1,*p2;while(head!=NULL&&head->data%2==0){p2=head;head=head->next;free(p2);}if(head==NULL)return NULL;p1=head;p2=head-> next;while(p2!=NULL){if(p2->data%2==0){p1->next=p2->next;free(p2);}elsep1=p2;p2=p1->next;}return head; }這個是查的沒有思路
學習總結:
上了兩節課,都不是很明白,完成作業也有一些問題,勉勉強強
編程總結:
討論了一些思路,檢查了下代碼,還行。
| 周 | 學習天數 | 代碼行數 | 知識點 | 疑惑點 |
| ----- | ------------ | ------------ | --------- | --------- |
| 十二 | 兩天 | 93 | 指針與函數 | 一些思路問題 |
轉載于:https://www.cnblogs.com/xulongfei/p/10883271.html
總結
- 上一篇: 云上建站快速入门:博客、论坛、CMS、电
- 下一篇: linux内核中的数据结构