cyalue

G

Jul 25th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. #include <algorithm>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. using namespace std;
  9.  
  10. int main() {
  11.     string n;
  12.     cin >> n;
  13.     int ans = 0;
  14.     int count = 0;
  15.     for (int i = 1; i < n.size(); i++) {
  16.         char a, b;
  17.         a = n[i - 1];
  18.         b = n[i];
  19.         if (isalpha(a) && isalpha(b)) { //isalpha() check if char isdigit() check if digit
  20.             ans++;
  21.             if (i == n.size() - 1) {
  22.                 ans++;
  23.             }
  24.         }
  25.         else if (isalpha(a) && isdigit(b)) {
  26.             count = b - '0';
  27.             if (i == n.size() - 1) {
  28.                 ans += count;
  29.             }
  30.         }
  31.         else if (isdigit(a) && isalpha(b)) {
  32.             ans += count;
  33.             count = 0;
  34.             if (i == n.size() - 1) {
  35.                 ans++;
  36.             }
  37.         }
  38.         else {
  39.             count *= 10;
  40.             count += (b - '0');
  41.             if (i == n.size() - 1) {
  42.                 ans += count;
  43.             }
  44.         }
  45.     }
  46.     cout << ans;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment