#13315: string轉int


d10631324@gapps.fg.tp.edu.tw (沙門氏菌)

學校 : 臺北市立第一女子高級中學
編號 : 71197
來源 : [59.120.19.253]
最後登入時間 :
2017-10-24 15:30:30
a038. 數字翻轉 | From: [1.160.61.119] | 發表日期 : 2018-01-31 13:16

#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
int main()
{
string s;
stringstream ss;
int x;
while(cin>>s)
{
reverse(s.begin(),s.end());
ss<<s;
ss>>x;
cout<<x<<endl;
ss.str("");
ss.clear();
}
return 0;
}

錯了幾次才看懂,題目的意思是

1230>>321   0000>>0 001230>>32100

希望不要有人跟我一樣蠢蠢的消錯零QQ

 
#13331: Re:string轉int


ysh58168@gmail.com (楊昊天)

學校 : 不指定學校
編號 : 74706
來源 : []
最後登入時間 :
2018-01-22 17:41:24
a038. 數字翻轉 | From: [110.50.137.84] | 發表日期 : 2018-02-03 15:55

#include
#include
#include
#include
using namespace std;
int main()
{
string s;
stringstream ss;
int x;
while(cin>>s)
{
reverse(s.begin(),s.end());
ss<<s;
ss>>x;
cout<<x<<endl;
ss.str("");
ss.clear();
}
return 0;
}

錯了幾次才看懂,題目的意思是

1230>>321   0000>>0 001230>>32100

希望不要有人跟我一樣蠢蠢的消錯零QQ


你好,可以請教一下,為甚麼原本是00250,轉換後會變成5200?

經過stringstream會把尾數為0的字元刪除嗎??

謝謝!!

 
ZeroJudge Forum