Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- string str, word = "", digit = "";
- getline(cin, str);
- str += ' ';
- int sumNumbers = 0;
- vector<string> words;
- for (int i = 0; i < str.length(); i++) {
- if (isdigit(str[i]) || str[i] == '-' && isdigit(str[i + 1])) {
- digit += str[i];
- }
- else if (str[i] != ' ') {
- word += str[i];
- }
- else {
- if (digit != "") {
- sumNumbers += stoi(digit);
- digit = "";
- }
- else {
- words.push_back(word);
- word = "";
- }
- }
- }
- cout << sumNumbers << endl;
- for (auto& w : words) {
- cout << w << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement