|
|
back to boardPlease explain where is the problem Posted by monteg 4 Jan 2012 17:51 #include <iostream> #include <string> using namespace std; void main() { string shifr; cin >> shifr; for (int n = 0;n<shifr.length();n++) { for (int i = 0;i<shifr.length()-1;i++) { if(shifr[i]==shifr[i+1]) { shifr.erase(i,2); } } } cout << shifr << endl; } I have got crash on test 2 Re: Please explain where is the problem First of all you will get TLE for your solution. Just use the Stack data structure and insert each characters one by one from the input string by comparing them with the lastly pushed character. If they match, then pop it off that lastly pushed character. Then printout the stack in reverse. That's all :) |
|
|