第十二周作業

2022-08-21 00:48:12 字數 4212 閱讀 1418

課程名稱

c語言程式設計2

作業要求

第十二周作業

我的課程目標

了解指標與函式的關係,掌握指標作為函式返回值

這個作業在哪個方面幫助我實現目標

了解了指標與函式的關係及指標與函式的關係

參考文獻

課本c語言程式設計

本題要求實現乙個函式,用於計算有n個元素的指標陣列s中最長的字串的長度。

函式介面定義:

int max_len( char *s, int n );

其中n個字串儲存在s中,函式max_len應返回其中最長字串的長度。

裁判測試程式樣例:

#include #include #include #define maxn 10

#define maxs 20

int max_len( char *s, int n );

int main()

; scanf("%d", &n);

for(i = 0; i < n; i++)

printf("%d\n", max_len(string, n));

return 0;

}/* 你的**將被嵌在這裡 */

輸入樣例:

4blue

yellow

redgreen

輸出樣例:

6

(1)實驗**
int max_len( char *s, int n )

}return strlen(s[w]);

}

(2)設計思路

流程圖(3)實驗遇到的問題及解決方案

無(4)執行結果截圖

本題要求實現乙個函式,統計學生學號鍊錶中專業為計算機的學生人數。鍊錶結點定義如下:

struct listnode ;

這裡學生的學號共7位數字,其中第2、3位是專業編號。計算機專業的編號為02。

函式介面定義:

int countcs( struct listnode *head );

其中head是使用者傳入的學生學號鍊錶的頭指標;函式countcs統計並返回head鍊錶中專業為計算機的學生人數。

裁判測試程式樣例:

#include #include #include struct listnode ;

struct listnode *createlist(); /*裁判實現,細節不表*/

int countcs( struct listnode *head );

int main()

/* 你的**將被嵌在這裡 */

輸入樣例:

1021202

2022310

8102134

1030912

3110203

4021205

#輸出樣例:

3

(1)實驗**
int countcs( struct listnode *head )

p=p->next;

} return n;

}

(2)設計思路

流程圖(3)實驗遇到的問題及解決方案

(4)執行結果截圖

本題要求實現兩個函式,分別將讀入的資料儲存為單鏈表、將鍊錶中偶數值的結點刪除。鍊錶結點定義如下:

struct listnode ;

函式介面定義:

struct listnode *createlist();

struct listnode *deleteeven( struct listnode *head );

函式createlist從標準輸入讀入一系列正整數,按照讀入順序建立單鏈表。當讀到−1時表示輸入結束,函式應返回指向單鏈表頭結點的指標。

函式deleteeven將單鏈表head中偶數值的結點刪除,返回結果鍊錶的頭指標。

裁判測試程式樣例:

#include #include struct listnode ;

struct listnode *createlist();

struct listnode *deleteeven( struct listnode *head );

void printlist( struct listnode *head )

printf("\n");

}int main()

/* 你的**將被嵌在這裡 */

輸入樣例:

1 2 2 3 4 5 6 7 -1

輸出樣例:

1 3 5 7

(1)實驗**
struct listnode *createlist()

return head;

}struct listnode *deleteeven( struct listnode *head )

if(f==0)

} return head->next;

}

(2)設計思路

流程圖(3)實驗遇到的問題及解決方案

(4)執行結果截圖

在西洋棋中,皇后是最厲害的棋子,可以橫走、直走,還可以斜走。棋手馬克斯·貝瑟爾 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 . . . .

我的參考文獻

遞迴求解迷宮最簡訊道的總步長。輸入乙個迷宮,求從入口通向出口的可行路徑中最短的路徑長度。為簡化問題,迷宮用二維陣列 int maze[10][10]來儲存障礙物的分布,假設迷宮的橫向和縱向尺寸的大小是一樣的,並由程式執行讀入, 若讀入迷宮大小的值是n(3

其中紅色的小方塊是障礙物,藍色的小方塊是空位,白色的小圓連起來是一條從入口到出口的通道,兩個圓之間代表乙個步長。

輸出樣例:

14

我的參考文獻

1.專案名稱:飛機大戰。目標:發射雷射。

2專案主體功能:飛機能發射子彈並且擊中目標,遊戲能判斷勝負,而且能判斷音效。

3線階段準備工作:對飛機控制的預習。

4成員:龍佳思,王俊傑,黃松

第十二周作業

例題1 includeusing namespace std struct date struct student int main stu1,stu2 stu1.num 1001 stu1.age 20 stu2 stu1 cout includeusing namespace std struc...

第十二周作業

1 多文件窗體 mdi form 功能演示 2 日期控制項datetimepicker功能演示 3 月曆控制項monthcalender功能演示 4 樹型列表控制項treeview功能演示 tn.expand 展開tn節點 treeview1.selectednode tn1 把新增節點設定為當前選...

第十二周作業

一.jpanel 方法型別 描述public jpanel 構造建立乙個預設的jpanel物件,使用流布局管理器 public jpanel layoutmanager layout 構造建立乙個指定布局管理器的jpanel物件 二.jsplitpane 三.jtabbedpane 四.jscrol...