### Saratov State University :: Online Contester

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

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

::webboard

 WA1. What is wrong?
Author: mikroz
ID: 059388
Problem: 397
Contest: 0
Date: 2013-09-01 16:42:26

Getting WA1 with Java. Could anybody suggest, what is wrong here?

import java.util.*;
import java.io.*;
import java.math.*;

class DNode
{
DNode next, prev;
char v;
}

public class Solution
{
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner(System.in);

char[] ch = in.next().toCharArray();

DNode node = new DNode();
node.prev = null;
node.next = null;

for (int i = 0; i < ch.length; i++)
switch(ch[i])
{
case 'L':
if (node.prev != null)
node = node.prev;
break;

case 'R':
if (node.next != null)
node = node.next;
break;

default:
DNode newNode = new DNode();

newNode.v = ch[i];
newNode.prev = node;
newNode.next = null;

if (node.next != null)
{
newNode.next = node.next;
node.next.prev = newNode;
}

node.next = newNode;
node = node.next;
break;
}

while (node.prev != null)
node = node.prev;

while (node != null)
{
System.out.print(node.v);
node = node.next;
}
System.out.println();
}
}