ACM練習題C 版答案記錄 Section 3

2021-10-02 02:41:53 字數 2780 閱讀 1514

最近複習c++,拿起acm從頭練,在此做個答案記錄,大家不要盲目複製哦,要有自己的思考哦

總體上,section3部分我花了不少時間呢,如果想破腦袋也想不到好辦法,可以去查閱網上的各種方法,不要侷限於自己的程式設計哦,做出來的題目,多看看別人的解答,也會有好處

1.3.1 排名問題花了些心思,複習了struct結構體的使用方法,程式設計過程中有兩個注意點

排名

#include#includeusing namespace std;

/**輸入:

人數 題數 分數線

各題分值

准考證號 解決的題數 對應的題號

第一行輸入為0時結束

輸出:通過的考生人數

通過的考生考號 分數

注:分數從高到低,分數相同時按考號排

*/typedef struct student

student;

int main()

cin>>exam_count>>pass_score;

int exam_points[10]; // 各題分值

for(int i=0; i>exam_points[i];

}struct student std[1000]; // 宣告一批學生變數

pass_count = 0;

for(int i = 0; i < std_count; i++)

// cout

for(int i = 0; i < pass_count; i++)

int kinds;

cin>>kinds;

while(kinds--)

for(int i = 0; i < 30; i++)

arrow += "+>";

count = arr[i];

while(count--)

int num[500], count = 0;

for(int i = 0; i < 500; i++)

for(int i =0; i < len; i++)

num[count] = num[count] * 10 + (str_num[i] - 48);

}else}}

for(int i = 0; i < count - 1; i++)

;bool compare(jewelry j1, jewelry j2)

int main()

//排序

sort(jewelries, jewelries+kinds, compare);

// for(int i = 0; i < kinds; i++)

//

else

}cout這題我學會了採用setprecision來精確小數字數

#include#include#includeusing namespace std;

/**輸入:

測試用例數量

有限金額 大公尺的種類

某種大公尺的單價 大公尺的重量

輸出:可買到的最大重量,保留兩位小數

*/struct rice2

;bool compare(rice2 r1, rice2 r2)

int main()

//排序

sort(rice, rice + kinds, compare);

// for(int i = 0; i < kinds; i++)

//

else

}cout<1.3.6 排序2  這一題,我學會了使用全排序方法,在格式上也花了點功夫才通過的

#include#include#include #includeusing namespace std;

/**輸入:

四個數字

輸出:由小到大輸出組合四位數

*/int main()

//排序

sort(a, a+4);

for(int i = 0; i < 4; i++)

row++;

} for(int k = 0; k < row; k++)

if(i == 0)

else

;bool compare(student std1, student std2)

int main()

}// 排序

sort(std, std+count,compare);

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

}i++;

cout<1.3.8 crixalis's equipment   這種題目就是在排序演算法上下功夫,要想好究竟按什麼順序排才合適

#include#includeusing namespace std;

/**輸入:

案例個數

體積 裝置的個數

各個裝置所佔體積 拖進洞至少要有的體積

輸出:yes 或者 no

*/struct equipment

;bool compare(equipment e1, equipment e2)

int main()

// 排序

物件導向練習題答案

答案整理如下 一 類和物件 1.定義乙個類demo,其中定義乙個求兩個資料和的方法,定義乙個測試了test,進行測試。class demo public int add class test 2.定義乙個長方形類,定義 求周長和面積的方法,然後定義乙個測試了test2,進行測試。class rect...

Java String練習題及答案

1.編寫程式將 jdk 全部變為大寫,並輸出到螢幕,擷取子串 dk 並輸出到螢幕 編寫程式將 jdk 全部變為大寫,並輸出到螢幕,擷取子串 dk 並輸出到螢幕 public static void main string args 2.編寫程式將string型別字串 test 變為 tset 2.編...

ACM 藍橋杯練習題

小a的學校有一些小河和一些湖泊,現在把它們統一看成水池,小a手裡有一張學校某處的地圖,這個地圖上僅標識了此處是否是水池,小a想知道這塊地方有多少個水池,現在,任務交給你了,請編寫程式算出該地圖中有幾個水池 第一行輸入乙個整數n,表示共有n組測試資料 每一組資料都是先輸入該地圖的行數m 輸出該地圖中水...