CodeChef (ONP)


Question:
http://www.codechef.com/problems/ONP/

Solutions:

#include
#include
using namespace std;

int main ()
{
int testCase;
cin >> testCase;

char input [410];
stack s;

gets (input);

while ( testCase– ) {

gets (input);

int length = strlen (input);

for ( int i = 0; i < length; i++ ) { if ( isalpha (input [i]) ) cout << input [i]; else if ( input [i] == ')' ) { cout << s.top (); s.pop (); } else if ( input [i] != '(' ) s.push (input [i]); } cout << endl; } return 0; } [/sourcecode]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s