blob: 10ded6914dc6330322fcb6b77f8dba9578935282 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <iostream>
class fillable_string: public std::string {
public:
void fill_digits();
};
void fillable_string::fill_digits() {
auto s = this->data();
char fill_char = ' ';
for (int i=0; i < this->size(); i++) {
if (std::isdigit(s[i])) {
s[i] += fill_char - '0'; // to shift the char val
} else {
fill_char = s[i];
}
}
}
int main() {
fillable_string inputs[]{
{"a1c1e1"},
{"a1b2c3d4"},
{"b2b"},
{"a16z"}
};
for (int i=0; i < 4; i++) {
std::cout << inputs[i] << " => ";
inputs[i].fill_digits();
std::cout << inputs[i] << '\n';
}
}
|