#45814: ????????????Giannis Antetokounmpo(Attackyourankle)


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

學校 : 臺北市私立薇閣高級中學
編號 : 252772
來源 : [60.248.154.139]
最後登入時間 :
2025-04-22 12:56:36
a307. NOIP2011 1.数字反转 -- NOIP2011普及组第一题 | From: [60.248.154.143] | 發表日期 : 2025-04-16 15:51

#include <bits/stdc++.h>
using namespace std;  

int main(){  
    int n;
    while(cin>>n){
        if(n==0){ // 如果n等於 0  
            cout<<"0"<<endl;
            continue; // 繼續下一次迴圈  
        }  
        if(n<0){ // 如果n是負數  
            cout<<"-"; // 輸出負號  
            n=abs(n); // 將n轉換為正數  
        }  
        int count=0,temp=0; // 初始化計數器count和暫存變數temp  
        while(n>=1){ // 當n大於或等於1時進入迴圈  
            temp=n%10; // 取得n的最後一位數字  
            n/=10; // 將n除以10,去掉最後一位數  
            if(temp!=0||count!=0){ // 如果temp不為0或已經有非零位數  
                cout<<temp;
                count++; // 增加計數器  
            }  
        }  
        cout<<endl; 
    }  
    return 0;
}  
 
ZeroJudge Forum