Ural_1654. Cipher Message(栈)

  /*我太二了, 上来就暴力,然后TLE两次。然后郁闷的去吃饭,回来一想栈的结构,10分钟AC。有种想撞墙的冲动!*/

//My Code:

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 200005;

char s[N];
char str[N];

int main() {
//freopen("data.in", "r", stdin);

int len, top, i;
while(cin.get(str, N) != NULL) {
len = strlen(str);
top = 0;
s[top++] = str[0];
for(i = 1; i < len; i++) {
if(str[i] != s[top-1]) {
s[top++] = str[i];
} else {
top--;
}
}
for(i = 0; i < top; i++)
printf("%c", s[i]);
printf("\n");
}
return 0;
}



posted @ 2011-11-18 19:22  AC_Von  阅读(254)  评论(0编辑  收藏  举报