### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

 Why wrong answer?! :-o
Author: Cimon
ID: 056184
Problem: 397
Contest: 0
Date: 2014-10-26 22:22:38

hi, this is my code for sgu 397. I used linked list and it works for lots of testes. but I dont know why do I still get wrong answer?!

#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Node{
char val;
Node *next;
Node *before;
};

//FirstNodeMaking:D
void initNode(Node *head, char n){
head->val = n;
head->next = NULL;
head->before = NULL;
}

//InsertAfterCursor
void insertAfter(Node *head, char n)
{
Node *newNode = new Node;
newNode->val = n;

//Last Node
if( head->next == NULL )
{
head->next = newNode;
newNode->before = head;
newNode->next = NULL;
}
//Not Last Node
else
{
newNode->next = head->next;
head->next->before = newNode;
newNode -> before = head;
head -> next = newNode;
}
}

int main(){
string s;
cin >> s;
bool flag = false;
bool cursorIsFirst = false;
Node* mainHead = new Node;

for(int i=0; i<s.size(); i++)
{
if( s[i]=='L' && flag )
{
Node *temp = new Node;

if( mainHead->before == NULL )
cursorIsFirst = true;

else
mainHead = mainHead->before;
}
else if( s[i]=='R' && flag)
{
if( mainHead->next != NULL )
mainHead = mainHead->next;
cursorIsFirst = false;
}
else if(!flag && s[i]!='L' && s[i]!='R')
{
flag = true;
initNode(mainHead, s[i]);
if( mainHead->next != NULL )
mainHead = mainHead->next;
}
else if(flag)
{
if( cursorIsFirst )
{
Node *temp = new Node;
temp->val = s[i];
temp->next = mainHead;
temp->before = NULL;
mainHead->before = temp;
mainHead = temp;
cursorIsFirst = false;
}
else
{
insertAfter(mainHead, s[i]);
if( mainHead->next != NULL )
mainHead = mainHead->next;
}
}
}

//Showing OutPut;
Node *cur = mainHead;
while( cur->before && flag )
cur = cur->before;

while( cur && flag )//!flag: momkene reshte faghat az L R bashe
{
cout << cur->val ;
cur = cur->next;
}
if( flag )
cout << endl;
return 0;
}

 ::Login form.login input{margin:2px;font-size:10px;} your id: password: Forgot password?

 ::News 22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553). 22.10.12 - After the start of the contest the statements in PDF will be available by the link.23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

 Server time: 2017-11-23 06:19:23 Online Contester Team © 2002 - 2016. All rights reserved.