#26137: C++ 陣列解法


gbossfamily2@gmail.com (羊)

學校 : 不指定學校
編號 : 158117
來源 : [42.73.42.98]
最後登入時間 :
2022-12-03 22:42:11
a038. 數字翻轉 | From: [42.73.143.88] | 發表日期 : 2021-07-18 15:40

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {

    long input , ans = 0 ,input2;

    long test = -1;

    

    

    while(cin>>input){

        if(input == 0){

            cout<<0<<endl;

        }else{

            input2 = input;

            while(input2 != 0){

                input2 /= 10;

                ans += 1;

            }

            long temp[ans];

            

            for(int i = 0;i < ans;i++){

                temp[i] = input % 10;

                input /= 10;

            }

            

            for(int i = 1;i < ans;i++){

                if(temp[0] == 0 && temp[1] != 0){

                    test = 0;

                }else

                if(temp[0] == 0 && temp[1] == 0){

                    if(temp[i] == 0){

                        test = i;

                    }else if(temp[i] != 0){

                        break;

                    }

                }

            }

            

            

            if(test > 0){

                for(long j = (test + 1);j < ans;j++){

                    cout<<temp[j];

                }

                

            }else if (test == 0){

                for(int j = 1;j < ans;j++){

                    cout<<temp[j];

                }

            }else{

                for(int j = 0;j < ans;j++){

                    cout<<temp[j];

                }

            }

 

            

        }

    }

    return 0;

}

 
ZeroJudge Forum