ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題
目前分類:ZERO JUDGE (10)
- Dec 03 Sun 2023 23:49
ZEROJUDGE C++程式解題2
- Dec 03 Sun 2023 23:49
ZEROJUDGE C++程式解題1
ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題ZEROJUDGE C++程式解題
- Dec 03 Sun 2023 11:58
ZEROJUDGE C++程式解題 a038
此題為出自zerojidge 基礎題a038 數字翻轉
以下是我寫出來的答案
(一)沒有struct版本
#include
using namespace std;
int reverseNumber(int num);
int main()
{
int num;
cin >> num;
int reversedNum;
reversedNum=reverseNumber(num);
cout << reversedNum << endl;
return 0;
}
int reverseNumber(int num)
{
// 當數字為 0 時直接輸出 0
if (num == 0)
{
cout << num << endl;
return 0;
}
// 反轉數字同時忽略尾部的零
int reversedNum = 0;
while (num > 0)
{
int digit = num % 10; // 獲取最後一位數
num /= 10; // 移除最後一位數
if (digit == 0 && reversedNum == 0)
{
// 忽略尾部的零
continue;
}
reversedNum = reversedNum * 10 + digit; // 將數字反轉
}
return reversedNum;
}
點我看程式碼
(二)有struct版本
- Dec 02 Sat 2023 23:27
ZEROJUDGE C++程式解題 a024
此題為出自zerojidge 基礎題a024
以下是我寫出來的答案
(一)沒有class版本
#include <iostream>
using namespace std;
// 函數:計算最大公因數
int gcd(int num1, int num2);
int main()
{
int num1, num2;
cin >> num1 >> num2;
cout << gcd(num1, num2) << endl;
return 0;
}
// 實現 gcd 函數
int gcd(int num1, int num2)
{
while (num2 != 0)
{
int temp = num2;
num2 = num1 % num2;
num1 = temp;
}
return a; // 返回計算結果
}
點我看程式碼
(二)有class版本
- Dec 02 Sat 2023 22:59
ZEROJUDGE C++程式解題 a022
此題為出自zerojidge 基礎題a022
以下是我寫出來的答案
#include <iostream>
using namespace std;
// 定義 isPalindrome 函數
void isPalindrome(string word) ;
int main()
{
string word;
cin >> word; // 正確讀取字串
isPalindrome(word); // 調用 isPalindrome 函數
return 0;
}
void isPalindrome(string word)
{
int length = word.length();
bool isPalin = true;
for (int i = 0; i < length / 2; i++)
{
if (word[i] != word[length - 1 - i])
{
isPalin = false; // 若找到不匹配的字符,則非迴文
break;
}
}
if (isPalin)
{
cout << "yes";
}
else
{
cout << "no";
}
}
點我看程式碼
- Dec 02 Sat 2023 22:35
ZEROJUDGE C++程式解題 a015
此題為出自zerojidge 基礎題a015
以下是我寫出來的答案
#include <iostream>
using namespace std;
int main()
{
int row, column;
// 當還有輸入時持續處理
while (cin >> row >> column)
{
// 動態分配二維陣列
int** matrix = new int*[row];
for (int i = 0; i < row; i++)
{
matrix[i] = new int[column];
}
// 從輸入讀取矩陣元素
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
cin >> matrix[i][j];
}
}
// 轉置矩陣
for (int i = 0; i < column; i++) {
for (int j = 0; j < row; j++) {
cout << matrix[j][i] << " ";
}
cout << endl;
}
delete[] matrix;
matrix=nullptr;
}
return 0;
}
點我看程式碼
- Nov 27 Mon 2023 22:53
ZEROJUDGE題目解析整理
- Nov 27 Mon 2023 22:50
ZEROJUDGE基本題庫
- Nov 25 Sat 2023 16:57
C++程式解題005
此題為出自zerojidge 基礎題005
以下是我寫出來的答案
#include <iostream>
using namespace std;
int main()
{
//先確認會有幾個數列
int n;
cin >> n;
//依次輸入每個數列的四個數字
for (int i = 0; i < n; i++)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
// 判斷數列類型
if (b - a == c - b && c - b == d - c)
{
// 等差數列
int diff = b - a;
cout << a << " " << b << " " << c << " " << d << " " << d + diff << endl;
}
else if (b / a == c / b && c / b == d / c)
{
// 等比數列
int ratio = b / a;
cout << a << " " << b << " " << c << " " << d << " " << d * ratio << endl;
}
}
return 0;
}
- Nov 25 Sat 2023 16:20
C++程式解題004