删掉连续的相同两个字母,直到不存在两个连续且相同的字母。
模拟一个栈即可。
#include<iostream> #include<cstdio> #include <cstring> #include <queue> #include <cmath> #include <algorithm> #include <cstdlib> #include <set> #include <vector> #include <map> using namespace std; #define eps 1e-7 #define INF 0x3fffffff #define L(u) (u<<1) #define R(u) (u<<1|1) #define MID(l,r) ((l+r)>>1) #define M 1000000009 const int maxn=200001; char s[maxn]; char stk[maxn]; int main() { int top=0; memset(stk,0,sizeof(stk)); scanf("%s",s); stk[top++]=s[0]; int len=strlen(s); for(int i=1;i<len;i++) { if(stk[top-1]==s[i]) { top--; } else { stk[top++]=s[i]; } } stk[top++]=0; printf("%s\n",stk); return 0; }