[問題] ZJ d098
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
ZJ d098
http://zerojudge.tw/ShowProblem?problemid=d098
希望得到的正確結果:
如題目
程式跑出來的錯誤結果:
只要有一個字串中含有非數字的字元
後面剩下的就加不到了
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
Dev-C++
有問題的code: (請善用置底文標色功能)
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
string s;
int i;
while(getline(cin,s))
{
stringstream ss(s),str;
string t;
int sum=0,z;
bool x=1;
while(ss>>t)
{
for(i=0;i<t.length();i++)
if(t[i]<48||t[i]>57)
{
x=0;
break;
}
if(x)
{
str.clear();
str<<t;
str>>z;
sum+=z;
}
}
cout<<sum<<endl;
}
//system("pause");
return 0;
}
補充說明:
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.23.148.201
→
07/13 11:38, , 1F
07/13 11:38, 1F
推
07/13 13:12, , 2F
07/13 13:12, 2F
推
07/13 13:42, , 3F
07/13 13:42, 3F