Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <utility>
- #include <algorithm>
- #include <string>
- #include <cctype>
- #include <stack>
- using namespace std;
- int main() {
- string n;
- cin >> n;
- int ans = 0;
- int count = 0;
- for (int i = 1; i < n.size(); i++) {
- char a, b;
- a = n[i - 1];
- b = n[i];
- if (isalpha(a) && isalpha(b)) { //isalpha() check if char isdigit() check if digit
- ans++;
- if (i == n.size() - 1) {
- ans++;
- }
- }
- else if (isalpha(a) && isdigit(b)) {
- count = b - '0';
- if (i == n.size() - 1) {
- ans += count;
- }
- }
- else if (isdigit(a) && isalpha(b)) {
- ans += count;
- count = 0;
- if (i == n.size() - 1) {
- ans++;
- }
- }
- else {
- count *= 10;
- count += (b - '0');
- if (i == n.size() - 1) {
- ans += count;
- }
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment