Problem Type: C++ STL list (Java LinkedList)
Implementation:
#include<bits/stdc++.h>
using namespace std;
/***
Tarequzzaman Khan
CSE'12
2012331514
*/
int main()
{
string s;
while(cin >>s)
{
int tag =0;
string sub="",output="";
for(int i=0; i<s.length(); i++)
{
if(s[i]=='[')
{
tag =1;
if(sub.compare("")!=0)
{
output=sub + output;
sub ="";
}
}
else if(s[i]==']')
{
tag = 0;
if(sub.compare("")!=0)
{
output=sub + output;
sub ="";
}
}
else if(tag==1)
{
sub += s[i];
}
else
{
output += s[i];
}
}
if(sub.compare("")!=0)
{
output = sub + output;
}
cout << output << endl;
}
}
Implementation:
#include<bits/stdc++.h>
using namespace std;
/***
Tarequzzaman Khan
CSE'12
2012331514
*/
int main()
{
string s;
while(cin >>s)
{
int tag =0;
string sub="",output="";
for(int i=0; i<s.length(); i++)
{
if(s[i]=='[')
{
tag =1;
if(sub.compare("")!=0)
{
output=sub + output;
sub ="";
}
}
else if(s[i]==']')
{
tag = 0;
if(sub.compare("")!=0)
{
output=sub + output;
sub ="";
}
}
else if(tag==1)
{
sub += s[i];
}
else
{
output += s[i];
}
}
if(sub.compare("")!=0)
{
output = sub + output;
}
cout << output << endl;
}
}
No comments:
Post a Comment