#33149: 字串解


yp11051024@yphs.tp.edu.tw (907-24吳卓昱)

學校 : 臺北市私立延平高級中學
編號 : 162949
來源 : [203.72.178.2]
最後登入時間 :
2024-04-16 13:48:13
a038. 數字翻轉 | From: [203.72.178.1] | 發表日期 : 2022-12-05 17:25

#include <iostream>

using namespace std;

int main()
{
    string a;
    cin>>a;
    bool n=true;
    if(a[0]=='0') cout<<'0';
    for(int i=a.length()-1;i>=0;i--)
    {
        if(a[i]!='0') {cout<<a[i];n=false;}
        else if(a[i]=='0'&& n==false) cout<<a[i];
    }

    return 0;
}

用字串倒轉輸出,並把0去掉

 
ZeroJudge Forum