1220-1 cpp ```cpp ``` #include <iostream> // 包含標準輸入輸出流的頭文件 #include <algorithm> // 包含算法庫的頭文件,提供排序等函數 using namespace std; // 使用標準命名空間,這樣可以直接使用 cout 和 cin int main() { int n; // 宣告一個整數 n 來存儲學生的數量 cin >> n; // 從標準輸入讀取學生數量 int scores[n]; // 宣告一個陣列來存儲學生的分數,大小為 n for (int i = 0; i < n; i++) { cin >> scores[i]; // 循環讀取每個學生的分數 } sort(scores, scores + n); // 使用 sort 函數將分數陣列由低到高排序 int lowestPassing = -1; // 宣告並初始化最低及格分數為 -1 int highestFailing = -1; // 宣告並初始化最高不及格分數為 -1 for (int i = 0; i < n; i++) { if (scores[i] >= 60) { // 檢查當前分數是否及格 lowestPassing = scores[i]; // 設置最低及格分數 break; // 中斷循環 } highestFailing = scores[i]; // 更新最高不及格分數 } for (int i = 0; i < n; i++) { cout << scores[i] << " "; // 輸出排序後的分數 } cout << endl; // 輸出換行符 if (highestFailing == -1) cout << "best case\n"; // 如果沒有不及格的學生,輸出 "best case" else cout << highestFailing << endl; // 否則輸出最高不及格分數 if (lowestPassing == -1) cout << "worst case\n"; // 如果沒有及格的學生,輸出 "worst case" else cout << lowestPassing << endl; // 否則輸出最低及格分數 return 0; // 程式結束 } --- #include <iostream> #include <cmath> using namespace std; int main() { string input; cin >> input; int a = 0; int b = 0; for (int i = 0; i < input.length(); i += 2) a += input[i] - 48; for (int i = 1; i < input.length(); i += 2) b += input[i] - 48; cout << abs(a - b) << endl; }  --- #include <iostream> // 包含標準輸入輸出流的頭文件 #include <algorithm> // 包含算法庫的頭文件,提供排序等函數 using namespace std; int main() { int nums[3]; for (int i = 0; i < 3; i++) { cin >> nums[i]; } sort(nums, nums + 3); cout << nums[0] << " " << nums[1] << " " << nums[2] << endl; if (nums[0] + nums[1] <= nums[2]) cout << "No"; else if (nums[0] * nums[0] + nums[1] * nums[1] < nums[2] * nums[2]) cout << "Obtuse"; else if (nums[0] * nums[0] + nums[1] * nums[1] == nums[2] * nums[2]) cout << "Right"; else if (nums[0] * nums[0] + nums[1] * nums[1] > nums[2] * nums[2]) cout << "Acute"; }
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up