標題:
2025/1/3 課堂重點(昀杰)
[打印本頁]
作者:
郭竑志
時間:
2025-1-3 17:45
標題:
2025/1/3 課堂重點(昀杰)
[課程重點]
clock() 函式
pow() 函式
倒數計時器
超級金頭腦 (一)
超級金頭腦 (二)
[今日作業]
超級金頭腦 (二)
作者:
陳昀杰
時間:
2025-1-3 19:01
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[5]={11,25,10,2,1};
for(int i=0;i<4;i++)
{
for(int j=i;j<4;j++)
{
if(a[j]<a[j+1])
{
swap(a[j],a[j+1]);
}
}
}
for(int k=0;k<5;k++)
{
cout<<a[k]<<endl;
}
return 0;
}
複製代碼
作者:
陳昀杰
時間:
2025-1-3 19:19
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[5]={11,25,10,2,1};
for(int i=0;i<5;i+=2)
{
for(int s=4-i;s>i;s--)
{
if(a[s]>a[s-1])
{
swap(a[s],a[s-1]);
}
}
for(int e=i;e<5-i;e++)
{
if(a[e]<a[e+1])
{
swap(a[e],a[e+1]);
}
}
}
for(int k=0;k<5;k++)
{
cout<<a[k]<<endl;
}
return 0;
}
複製代碼
作者:
陳昀杰
時間:
2025-1-3 19:50
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int s=0,st=0,e=0;
cout<<"sec?"<<endl;
cin>>s;
st=clock();
while(e<s*1000)
{
e=clock()-st;
}
cout<<"over"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳昀杰
時間:
2025-1-3 19:55
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int p;
srand(time(0));
cout<<rand()%49+51<<endl;
cout<<rand()%49+51<<endl;
cout<<"sum?"<<endl;
cin>>p;
}
複製代碼
作者:
陳昀杰
時間:
2025-1-4 22:22
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
system("cls");
cout << "=========================" << endl;
cout << " 超級金頭腦 遊戲 " << endl;
cout << "=========================" << endl;
cout << "遊戲規則:" << endl;
cout << "1. 每位玩家需要計算兩個隨機數的和。" << endl;
cout << "2. 每次回答正確可得 10 分,錯誤不得分。" << endl;
cout << "3. 所有玩家完成後,將顯示排名。" << endl;
cout << "=========================\n" << endl;
int numPlayers;
cout << "請輸入參賽人數:";
cin >> numPlayers;
string playerNames[numPlayers];
int playerScores[numPlayers] = {0};
cout << "\n請輸入每位參賽者的姓名:\n";
for (int i = 0; i < numPlayers; i++) {
cout << "參賽者 " << i + 1 << ":";
cin >> playerNames[i];
}
cout << "\n所有參賽者請就位!遊戲即將開始...\n";
cout << "輸入任何內容並按 Enter 開始測驗!" << endl;
string temp;
cin >> temp;
system("cls");
srand(time(0));
cout << "\n測驗開始!每位玩家將回答 5 道題目。\n" << endl;
for (int i = 0; i < numPlayers; i++) {
cout << "玩家:" << playerNames[i] << ",準備開始!" << endl;
for (int j = 1; j <= 5; j++) {
int num1 = rand() % 49 + 51;
int num2 = rand() % 49 + 51;
int correctAnswer = num1 + num2;
cout << "題目 " << j << ": " << num1 << " + " << num2 << " = ? ";
int userAnswer;
cin >> userAnswer;
if (userAnswer == correctAnswer) {
cout << "正確!+10 分!" << endl;
playerScores[i] += 10;
} else {
cout << "錯誤!正確答案是 " << correctAnswer << "。" << endl;
}
}
cout << "玩家 " << playerNames[i] << " 測驗結束,得分:" << playerScores[i] << " 分。\n" << endl;
cout << "輸入任何內容並按 Enter 以繼續到下一位玩家...";
cin >> temp;
system("cls");
}
int indices[numPlayers];
for (int i = 0; i < numPlayers; i++) {
indices[i] = i;
}
for (int i = 0; i < numPlayers - 1; i++) {
for (int j = 0; j < numPlayers - i - 1; j++) {
if (playerScores[indices[j]] < playerScores[indices[j + 1]]) {
swap(indices[j], indices[j + 1]);
}
}
}
system("cls");
cout << "\n=========================" << endl;
cout << " 排名結果 " << endl;
cout << "=========================" << endl;
for (int i = 0; i < numPlayers; i++) {
cout << i + 1 << ". " << playerNames[indices[i]] << " - " << playerScores[indices[i]] << " 分" << endl;
}
cout << "=========================\n" << endl;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2