#46230: C++_STL_字串翻轉_前端除零


aa6610 (unknown)

學校 : 不指定學校
編號 : 301767
來源 : [210.240.11.22]
最後登入時間 :
2025-06-16 10:53:22

#include <bits/stdc++.h>
using namespace std;
int main()
{
   
    string s;
    getline(cin,s);  //輸入一整個字串
    
    reverse(s.begin(),s.end()); //翻轉
  
    if(s.find_first_not_of('0')==string::npos){ //如果S是全零字符串,就返回string::npos
        cout<<"0"<<endl;
    }else{
        s.erase(0, s.find_first_not_of('0'));//否則,就將前面的0清除
        cout<<s<<endl;
    }
   

    return 0;
}