Last active
November 5, 2019 08:24
-
-
Save pinglunliao/7f72ab04600b01f9a5b8 to your computer and use it in GitHub Desktop.
d018: 字串讀取練習 FYI: https://yunlinsong.blogspot.com/2016/01/blog-post_26.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
using namespace std; | |
int main() | |
{ | |
string str; | |
while(getline(cin, str)) | |
{ | |
int serial; | |
char dummy; | |
double real; | |
double result = 0; | |
istringstream buffer(str); | |
while(buffer >> serial >> dummy >> real) | |
{ | |
//cout << serial << dummy << real << " "; | |
if( serial & 1 ) | |
result += real; | |
else | |
result -= real; | |
//cout << result << endl; | |
} | |
cout << result << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment