Created
June 18, 2013 17:14
-
-
Save rigibun/5807354 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<deque> | |
#include<queue> | |
using namespace std; | |
deque<char> deq; | |
void check(){ | |
//cout << "check" << endl; | |
deque<char> que; | |
int j = deq.size(); | |
for(int i = 0; i < j; i++){ | |
//cout << deq.front() << ' ' << que.back() << endl; | |
if(que.size() == 0 || deq.front() != que.back()){ | |
que.push_back(deq.front()); | |
deq.pop_front(); | |
} | |
else{ | |
deq.pop_front(); | |
que.pop_back(); | |
} | |
} | |
j = que.size(); | |
for(int i = 0; i < j; i++){ | |
deq.push_back(que.front()); | |
que.pop_front(); | |
} | |
} | |
int main(void){ | |
int n; | |
cin >> n; | |
char str[55]; | |
cin >> str; | |
for(int i = 0; i < n; i++){ | |
if(deq.size() < 2){ | |
deq.push_back(str[i]); | |
}else{ | |
bool b = false; | |
if(str[i] == deq.front()) b = true; | |
else if(str[i] == deq.back()) b = false; | |
else { | |
for(int j = 0; j < deq.size() / 2; j++){ | |
if(deq.at(j) == deq.at(deq.size()-1 - j)) continue; | |
for(int k = i; k < n; k++){ | |
if(str[k] == deq.at(j)){ | |
break; | |
} | |
if(str[k] == deq.at(deq.size()-1 - j)){ | |
b = true; | |
break; | |
} | |
} | |
} | |
} | |
if(b){ | |
deq.push_front(str[i]); | |
}else{ | |
deq.push_back(str[i]); | |
} | |
} | |
//for(int j = 0; j < deq.size(); j++){ | |
// cout << deq.at(j); | |
//} | |
//cout << endl; | |
check(); | |
} | |
cout << deq.size() << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment