想看題目請點我
#include <iostream> #include <sstream> using namespace std; int main() { string s1 ; while(getline(cin, s1)) { string s2 ; long int x = 0 , value = 0 ; for(int i = 0 ; i <= s1.length() ; i++) { if(s1[i] == ' '|| s1[i] == '\0') { stringstream ss(s2); ss >> x; value += x ; //Init s2 = "" ; x = 0 ; } else { s2 += s1[i]; } } cout << value << endl ; } return 0; }