Pages

Sunday, August 14, 2011

d098: Stringstream運用練習(C++)


#include
#include
#include
using namespace std;

bool IsAllInt(string str);


int main()
{
string input;

while(getline(cin,input))
{
int sum=0;
stringstream stream(input);

while(stream)
{
string word;
stream>>word;
if(IsAllInt(word))
{
sum += atoi(word.c_str());
}
}
cout< }
return 0;
}

bool IsAllInt(string str)
{
for(int i=0;i {
if(!isdigit(str[i]))
return 0;
}
return 1;
}

No comments:

Post a Comment