kirtidabas's blog

By kirtidabas, history, 5 years ago, In English

my code works on my ide but gives run time error on submission on codeforces.I can't understand why is this happening. Any help is appreciated.

here is my code:-

import java.util.*; public class leftHand_RightHand {

public static void main(String[] args) {
Scanner scn = new Scanner(System.in);

scn.nextLine();
String str=scn.nextLine();

// System.out.println(str+" "+str.length());

for(int i=0,j=(str.length()/2);i<(str.length()/2) && j<str.length();i++,j++) {
    if((str.charAt(i)=='L' && str.charAt(j)=='L') || ( str.charAt(i)=='R' &&  str.charAt(j)=='R'))
       System.out.println((i+1)+" "+(j+1));

    else if( str.charAt(i)=='L'&&  str.charAt(j)=='R')  
       System.out.println((i+1)+" "+(j+1));

    else if( str.charAt(i)=='R'&& str.charAt(j)=='L') 
       System.out.println((j+1)+" "+(i+1));
}

}

}

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Code works well. Mb you forgot input?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    the code works on ide but shows runtime error on submission

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 4   Vote: I like it +3 Vote: I do not like it

      Ok, I see. You must read and write in "input.txt" and "output.txt"
      As I remember, it may be made with:

      BufferedReader in = new BufferedReader(new FileReader("input.txt"));
      PrintWriter out = new PrintWriter("output.txt");

      And in code you must use next: String s = in.readLine();
      out.println(s);
      out.close();

      Or you may just use this template 55495328

      • »
        »
        »
        »
        5 years ago, # ^ |
        Rev. 2   Vote: I like it +3 Vote: I do not like it

        In the end of your method main, you must print line out.close() — is will close your output stream.
        Something like that : 55495666