目前分類:ZERO JUDGE (10)

瀏覽方式: 標題列表 簡短摘要

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++程式解題


戰昇 發表在 痞客邦 留言(0) 人氣()

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++程式解題

 


戰昇 發表在 痞客邦 留言(0) 人氣()

此題為出自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版本

戰昇 發表在 痞客邦 留言(0) 人氣()

此題為出自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版本

戰昇 發表在 痞客邦 留言(0) 人氣()

此題為出自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";
    }
}






點我看程式碼

 

戰昇 發表在 痞客邦 留言(0) 人氣()

此題為出自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;
}




點我看程式碼

 

戰昇 發表在 痞客邦 留言(0) 人氣()

以下是我整理的ZEROJUDGE題目解析
有問題都可以底下留言

 

基本題庫

 
 

 

戰昇 發表在 痞客邦 留言(0) 人氣()

以下是我目前寫的基本題庫參考答案

 
 
 
a004. 文文的求婚
a005. Eva 的回家作業
 

 


戰昇 發表在 痞客邦 留言(0) 人氣()

 

此題為出自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;
}



戰昇 發表在 痞客邦 留言(0) 人氣()

此題為出自zerojidge 基礎題004

點我觀看題目

以下是我寫出來的答案

 


#include <iostream>
using namespace std;


int main()
{
        int year;//因為year是整數 
        
        while(cin>>year)//只要使用者持續輸入,就會一直執行迴圈 
        {
        //此為判斷是否為閏年 
                if((year%4==0&&year%100!=0)||year%400==0)
                        cout<<"閏年"<<"\n";//記得要用換行符號 
                else
                        cout<<"平年"<<"\n";
                
        }
        return 0;

}

戰昇 發表在 痞客邦 留言(0) 人氣()