Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int rec(string s, int i) {
- if(i == -1) {
- return 0;
- }
- int cifra = 0;
- if(isdigit(s[i])) {
- cifra = (s[i] - '0');
- return rec(s, i - 1) * 10 + cifra;
- }
- else {
- return rec(s, i - 1);
- }
- }
- int main()
- {
- string s;
- cin >> s;
- cout << rec(s, s.size() - 1) << endl;
- return 0;
- }
- /*
- rec(123abc45, 7) = rec(123abc45, 6) * 10 + 5 = 1234 * 10 + 5 = 12345
- rec(123abc45, 6) = rec(123abc45, 5) * 10 + 4 = 123 * 10 + 4 = 1234
- rec(123abc45, 5) = rec(123abc45, 4) = 123
- rec(123abc45, 4) = rec(123abc45, 3) = 123
- rec(123abc45, 3) = rec(123abc45, 2) = 123
- rec(123abc45, 2) = rec(123abc45, 1) * 10 + 3 = 12 * 10 + 3 = 123
- rec(123abc45, 1) = rec(123abc45, 0) * 10 + 2 = 1 * 10 + 2 = 12
- rec(123abc45, 0) = rec(123abc45, -1) * 10 + 1 = 0 * 10 + 1 = 1
- rec(123abc45, -1) = 0
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement