| 2 | using namespace std; |
| 3 | |
| 4 | int main(int argc, char const *argv[]) { |
| 5 | ios_base::sync_with_stdio(false); |
| 6 | cin.tie(NULL); |
| 7 | |
| 8 | string line; |
| 9 | getline(cin, line); |
| 10 | |
| 11 | int total_of_a = count(line.begin(), line.end(), 'a'); |
| 12 | int total_not_a = line.size() - total_of_a; |
| 13 | |
| 14 | // First check to see if the number of 'a' is greater than non 'a' |
| 15 | if (total_not_a < total_of_a){ |
| 16 | printf("%d\n", line.size()); |
| 17 | return 0; |
| 18 | }else{ |
| 19 | string::iterator it = line.begin(); |
| 20 | // The while delete the non 'a' until the number of 'a' be greater |
| 21 | // The ideia is the iterator go through the string and delete |
| 22 | // where is differente of 'a' |
| 23 | // The iterator does not have the problem like indexing has |
| 24 | // when you delete something. |
| 25 | while (total_of_a <= total_not_a){ |
| 26 | if (*it != 'a'){ |
| 27 | line.erase(it); |
| 28 | }else it++; // When the iterator finds the 'a' it continues |
| 29 | total_not_a = line.size() - total_of_a; // Recalculate |
| 30 | } |
| 31 | } |
| 32 | printf("%d\n", line.size()); |
| 33 | return 0; |
| 34 | } |
nothing calls this directly
no outgoing calls
no test coverage detected