cf D. Alternating Current

http://codeforces.com/contest/344/problem/D

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <stack>

 4 #include <algorithm>

 5 using namespace std;

 6 

 7 char str[100001];

 8 int main()

 9 {

10     stack<char>q;

11     scanf("%s",str);

12     int k=strlen(str);

13     for(int i=0; i<k; i++)

14     {

15         if(q.empty())

16         {

17             q.push(str[i]);

18         }

19         else if(str[i]==q.top())

20         {

21             q.pop();

22         }

23         else if(str[i]!=q.top())

24         {

25             q.push(str[i]);

26         }

27     }

28     if(!q.empty()) printf("No\n");

29     else printf("Yes\n");

30     return 0;

31 }
View Code

 

你可能感兴趣的:(current)