北京理工大學複試上機 2001A

2022-08-21 21:00:20 字數 1197 閱讀 2696

1、編寫程式,計算下列分段函式 y=f(x)的值。

y = -x + 2.5, 0 <= x < 2

y = 2 - 1.5 (x - 3) (x - 3), 2 <= x < 4

y = x / 2 - 1.5, 4 <= x < 6

#include using

namespace

std;

intmain()

else

if(x >= 2 && x < 4

)

else

if(x >= 4 && x < 6

)

else

}return0;

}

2、編寫程式,讀入乙個整數 n。若 n 為非負數,則計算 n 到 2n 之間的整數和;若 n 為乙個負數,則求 2n 到 n 之間的整數和。

#include using

namespace

std;

intmain()

}else

}cout

<< sum <}

return0;

}

3、設 n 是乙個四位數,它的 9 倍恰好是其反序數(例如:1234 的反序數是 4321),求 n 的值。

#include using

namespace

std;

intmain() }}

}return0;

}

4、n 個人圍成一圈順序編號,從 1 號開始按 1、2、3 順序報數,報 3 者退出圈外,其餘的人再從 1、2、3 開始報數,報 3 的人再退出圈外,依次類推。請按退出順序輸出每個退出人的原序號。要求使用環形鍊錶程式設計。

#include using

namespace

std;

struct

node

;int

main()

p -> next =head;

int cnt = 1

;

while(head -> next !=head)

else head = head ->next;

}cout

<< head -> data <}

return0;

}

北京理工大學複試上機 2020

ps 2020的是夏令營試題 1 題目 給你乙個 m n 大小的矩陣,每個點有 0,1,2 三種取值 0 代表障礙物,1代表白紙,2 代表墨滴。每一秒墨滴可以向其上下左右擴散,將四周的白紙染色,被染色之後的白紙可以繼續向四周擴散,以此類推。問經過幾秒,矩陣中所有的白紙都被染色。如果可以,則輸出擴散時...

北京理工大學複試上機 2015

1 圖形輸出 輸入 0 9 內的奇數,輸出用 組成的正方形中間掏出來乙個空的菱形。我是按照這種輸出的 9 8 include using namespace std intmain cout for int i n 2 i n i cout return0 2 有3個字母a,b,c 你輸入乙個數字,...

北京理工大學複試上機 2010

1 輸入一串整數,輸入命令排序!輸入 a t 在這串整數後面新增整數 t,輸入 c m n 有 n 替換 m,輸入 d t 刪除 t,輸入 s 排序。include include include include using namespace std int tonum string s,int ...