小程式練手(c )

2021-06-27 12:20:32 字數 2299 閱讀 1864

給定乙個陣列input 

,如果陣列長度n為奇數,則將陣列中最大的元素放到 output 陣列最中間的位置,如果陣列長度n為偶數,則將陣列中最大的元素放到 output 陣列中間兩個位置偏右的那個位置上,然後再按從大到小的順序,依次在第乙個位置的兩邊,按照一左一右的順序,依次存放剩下的數。 

例如:input =    output = ; 

input =     output = 

#include #include using namespace std;

int input[100],output[100];

bool compare(int a,int b)

int main()

sort(input,input+n,compare);

i=n/2;

output[i]=input[0];

a=b=i;

while(j作業系統任務排程問題。

作業系統任務分為系統任務和使用者任務兩種。其中,系統任務的優先順序 < 50,使用者任務的優先順序 >= 50且 <= 255。優先順序大於255的為非法任務,應予以剔除。現有一任務佇列task,長度為n,task中的元素值表示任務的優先順序,數值越小,優先順序越高。函式scheduler實現如下功能,將task 中的任務按照系統任務、使用者任務依次存放到 system_task 陣列和 user_task 陣列中(陣列中元素的值是任務在task 陣列中的下標),並且優先順序高的任務排在前面,陣列元素為-1表示結束。 

例如:task =     system_task =     user_task = 

#include //此段**有些問題,基本功能已實現

#include #include using namespace std;

map w;

int main()

if(task[i]>=50&&task[i]<=255)

}sort(system_task,system_task+j);

sort(user_task,user_task+k);

for(i=0;i::iterator it = w.find(system_task[i]);

system_task[i]=it->second;

cout<::iterator it = w.find(user_task[i]);

user_task[i]=it->second;

cout《字串替換:編寫乙個字串替換函式,如strsrc為原字串,strfind是待替換的字串,strreplace為替換字串。

舉個直觀的例子吧,如:「abcdefghijklmnopqrstuvwxyz」這個字串,把其中的「rst」替換為「ggg」這個字串,結果就變成了:

abcdefghijklmnopqggguvwxyz

#include #include using namespace std;

string strsrc,strfind,strreplace;

int main()

int verifyidcard(string str)

return 0;

}int main()

#include #include #include using namespace std;

int k=0,n=0;

void take_num(const string strin,int *outarray)

{ int sum=0;

for(int i=0;i>str;

getline(cin,str); //若要讀入帶空格的串,用getline(cin,str);替換cin>>str;

int *outarray = new int[str.length()];

take_num(str,outarray);

cout《通過鍵盤輸入100以內正整數的加、減表示式,請編寫乙個程式輸出運算結果字串。

輸入字串的格式為:「運算元1 運算子 運算元2」,「運算元」與「運算子」之間以乙個空格隔開。

補充說明:

1. 運算元為正整數,不需要考慮計算結果溢位的情況。

2. 若輸入算式格式錯誤,輸出結果為「0」。

示例 輸入:「4 + 7」  輸出:「11」

輸入:「4 - 7」  輸出:「-3」

輸入:「9 ++ 7」  輸出:「0」 注:格式錯誤

#include#include#includeusing namespace std;

int a[3];

int calculate (string str)

{ int sum = 0,k=0;

for(int i=0;i

練手小程式(四)

這次的練手程式依然來自於knight lab的部落格文章five mini programming projects for the python beginner,任務的名字叫做textbased adventure game,也就是文字冒險遊戲 目標 我們的目標是完整的建立乙個文字小遊戲,這個小...

python練手小程式

python小白 usr bin env python coding utf 8 time 2019 11 5 8 53 author october file py 整數序列求和 n input 請輸入整數n sum 0 for i in range int n sum i 1print 1到n求...

邏輯練練手小程式

寫個練練手,自己增加要求增加寫,至上而下寫 小程式要求 1.使用者可能輸入內容中前後多按了空格進行去除 2.使用者不按規定輸入內容返還輸入,並給與警告提示 3.需要記錄使用者的資訊,輸入次數規定3 4.提示密碼錯誤,賬號錯誤,或者兩者都錯 4.獎品可選猜對了可以獲取2個 5.猜的機會有3次 6.拿了...