Pages

Monday, August 15, 2011

d018. 字串讀取練習


#include
#include
#include
using namespace std;

const int SIZE = 3000;

int main()
{
char input[SIZE];
while(cin.getline(input,SIZE))
{
double sum=0;
char* pch;
pch = strtok(input," :");
while(pch !=NULL)
{
bool IsOdd;
if((int)atoi(pch)%2==1)
IsOdd=1;
else IsOdd=0;

pch = strtok(NULL," :");

if(IsOdd)
sum += atof(pch);
else
sum -= atof(pch);

pch = strtok(NULL," :");
}

cout< }
return 0;
}

No comments:

Post a Comment