#19245: c++ AC (stringstream解)


089487 (089487)

學校 : 國立臺灣師範大學附屬高級中學
編號 : 82069
來源 : [220.130.10.185]
最後登入時間 :
2024-04-01 11:16:18
b982. YoJudge 預練(空間之章) -- b961YoJudge | From: [223.137.129.110] | 發表日期 : 2019-09-19 20:07

#include<iostream>
#include<sstream>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
while(cin>>s)
{
bool f=false;
for(int i=0;i<s.length();i++)
{
if(s[i]=='.'||s[i]==' ') continue;
if(!f)
{
if(s[i]<'0'||s[i]>'9') s.insert(s.begin()+i,' '),i++,f=1;
}
else
{
if(s[i]>='0'&&s[i]<='9') s.insert(s.begin()+i,' '),i++,f=0;
}
//cout<<f<<endl;

}
stringstream ss(s);
long long int time=0;s.clear();
double d;
while(ss>>d>>s)
{
if(s=="gb"||s=="g") time+=(d*1000000000*8);
else if(s=="m"||s=="mb") time+=(d*8*1000000);
else if(s=="k"||s=="kb") time+=(d*1000*8);
else if(s=="byte")
{
if(d!=(int)d) time+=(int)d*8+(d-(int)d)*10;
else time+=d*8;
}
else time+=d;
}
cout<<time<<endl;
}
}

AC (2ms, 380KB)
 
ZeroJudge Forum