81A - Plug-in - CodeForces Solution


implementation *1400

Please click on ads to support us..

Python Code:

a=[i for i in input()]


res=list()

for c in a:
    if res:
        if c==res[-1]:
            res.pop()
        else:
            res.append(c)
    else:
        res.append(c)

print("".join(res))
			 			 	 	 		 		   		  	 			

C++ Code:

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    
   string s ; 
   
   cin >> s ;
   
   stack <char> stack ;
   
  
   
   stack.push(s[0]) ;
 
   
   for( int i = 1 ; i < s.size() ; i++ )
   {
       
         while( !stack.empty() && s[i] == stack.top() )
         {
             stack.pop() ;
                i++ ;
         }
   
     
        
            
         if( i < s.size())
         {
         
             
               stack.push(s[i]) ;
         
         }
    
   }
   int t ;
   t = stack.size() ;
   char arr[t] ;
 
  for( int i = 0 ; i <  t ; i++ )
  {
      arr[i] = stack.top() ; 
      stack.pop() ;
  }
 
   for( int i = (t - 1) ; i >= 0 ; i-- )
  {
     cout << arr[i] ;
  }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns
1374C - Move Brackets
1476A - K-divisible Sum
1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson