#45545: ejay


1121226@stu.wghs.tp.edu.tw (Arthur✨小蜜蜂)

學校 : 臺北市私立薇閣高級中學
編號 : 252772
來源 : [60.248.154.139]
最後登入時間 :
2025-04-07 12:53:35
d318. 11185 - Ternary -- UVa11185 | From: [60.248.154.139] | 發表日期 : 2025-03-14 12:57

#include <bits/stdc++.h>  
using namespace std;
string a(int n){ // 建立一個函式庫計算十進位轉三進位
    if(n==0) return "0"; // 如果n等於0則回傳0
    string s="";
    while(n>0){
        int m=n%3; // 將n除以3的餘數m
        s=to_string(m)+s; // 將n除以3的餘數加到s後面
        n/=3; // 將n除以3
    }
    return s; // 回傳s
}
int main() {  
    int n;
    while(cin>>n&&n>=0){
        string t=a(n); // 將n傳入函式a
        cout<<t<<endl;
    }
}  
 
#45572: Re: ejay


1121232@stu.wghs.tp.edu.tw (Ian911436)

學校 : 臺北市私立薇閣高級中學
編號 : 258883
來源 : [60.248.154.139]
最後登入時間 :
2025-04-07 12:40:46
d318. 11185 - Ternary -- UVa11185 | From: [60.248.154.143] | 發表日期 : 2025-03-19 15:24

#include   
using namespace std;
string a(int n){ // 建立一個函式庫計算十進位轉三進位
    if(n==0) return "0"; // 如果n等於0則回傳0
    string s="";
    while(n>0){
        int m=n%3; // 將n除以3的餘數m
        s=to_string(m)+s; // 將n除以3的餘數加到s後面
        n/=3; // 將n除以3
    }
    return s; // 回傳s
}
int main() {  
    int n;
    while(cin>>n&&n>=0){
        string t=a(n); // 將n傳入函式a
        cout<endl;
    }
}  

11 題 ans : b

 
ZeroJudge Forum