Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- using namespace std;
- int main()
- {
- string s;
- while(cin>>s){
- bool isOk=true;
- stack<string> stk;
- for( int i=s.length()-1 ; i>=0 ; i--){
- string sentence;
- if(s[i]>='p' && s[i]<='z'){
- sentence = s[i];
- stk.push(sentence);
- }
- else if(s[i] == 'N'){
- if( stk.empty() ){
- isOk = false;
- break;
- }
- sentence = 'N' + stk.top();
- stk.pop();
- stk.push(sentence);
- }
- else if( s[i] == 'C' || s[i] == 'D' || s[i] == 'E' || s[i] == 'I' ){
- if(stk.size()<2 ){
- isOk = false;
- break;
- }
- sentence = stk.top();
- stk.pop();
- //sentence = s[i]+ sentence + stk.top();
- sentence = s[i]+ stk.top() + sentence;
- stk.pop();
- stk.push(sentence);
- }
- else{
- isOk = false;
- break;
- }
- }
- if(stk.size()!=1){
- isOk = false;
- }
- cout<<((isOk)? "YES":"NO")<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement