0

How can I reduce the amount of memory that my program takes up after compilation?

#include <iostream> #include<string> using namespace std; void printpatt(string a, int i); int main() { int i = 0; string a = ""; while (getline(cin, a)) { printpatt(a, i); i = 0; } return 0; } void printpatt(string a, int i) { string temp = ""; while (a[i] != '\0') { if (a[i] == 'a' && a[i + 1] == 'b' && (a[i + 2] == 'b' || a[i + 2] == 'c')) { temp += a[i]; temp += a[i + 1]; i += 2; } else if (a[i] == 'b' && a[i - 1] == 'b' && a[i - 2] != 'c' && (a[i - 2] == 'a' || a[i - 2] == 'b') && (a[i + 1] == 'b' || a[i + 1] == 'c')) { temp += a[i]; i++; } else if (a[i] == 'c' && a[i - 1] == 'b' && (a[i - 2] == 'a' || a[i - 2] == 'b') && a[i - 3] != 'c') { temp += a[i]; if (temp.length() > 2 && temp[0] == 'a' && temp[temp.length() - 1] == 'c') { cout << temp << endl; temp = ""; i++; } } else { temp = ""; i++; } } }

1st Dec 2020, 5:35 AM
Faezeh Alinejad
Faezeh Alinejad - avatar
1 Resposta
+ 2
You could use 'Memory' and to delete 'delete[] memory' but you can find more help right here https://stackoverflow.com/questions/15837535/how-to-clear-the-dynamically-allocated-memory-which-is-in-heap
1st Dec 2020, 6:19 AM
Julian Bents
Julian Bents - avatar