dheeraj1995's blog

By dheeraj1995, 7 years ago, In English

while on submitting program i get
Source should satisfy regex [^{}]*public\s+(final)?\s*class\s+(\w+).* please help me to get out of this error here is my program for quest. 227B contest round#140 div 2 import java.io.*; import java.util.*; class IputReader { private int curchar; private int numchar; private byte[] buf = new byte[1024]; private InputStream stream; public IputReader(InputStream stream) { this.stream = stream; } public int read() throws IOException { if(curchar>=numchar) { curchar=0; numchar = stream.read(buf); if(numchar<=0) return -1; } return buf[curchar++]; } public int nextInt() throws IOException { int c = read(); while(isSpaceChar(c)) c = read(); int sgn=1; /* if(c=='-') { sgn=-1; c = read(); } */int res = 0; do{ res *= 10; res += c&15; c = read(); }while(!isSpaceChar(c)); return res*sgn; } public static boolean isSpaceChar(int c) { return c==' '|| c=='\n' || c=='\t' || c=='\r' || c==-1; } } public class approach { public static void main(String args[])throws IOException { IputReader br = new IputReader(System.in); PrintWriter pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int k; System.out.println("enter:"); int n=br.nextInt(); ArrayList ob=new ArrayList(); //StringTokenizer input=new StringTokenizer(br.readLine()); for(int i=0;i<n;i++) { k=br.nextInt(); ob.add(k); } int m=br.nextInt(); int a=0; int b=0; //input=new StringTokenizer(br.readLine()); for(int i=0;i<m;i++) {

k=br.nextInt();
        int pos=ob.indexOf(k);
        a+=pos+1;
        b+=n-pos;
    }
    System.out.println(a+" "+b);
}

}

 
 
 
 
  • Vote: I like it
  • -6
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You have two classes in your file, it should be only one. Just put class IputReader inside approach class and that is it.

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Do you mean that the second class has to be a inner class? If that so, I don't think this is the case, because my template has 4 classes in it and none of them are inner class. What I've found from this regex error is that the first class has to made public in the solution. Here's one of my submissions for reference: http://codeforces.com/contest/412/submission/6409093. Please correct me if I'm wrong.

»
7 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Instead of using two different classes, use nesting of classes... so that your IputReader class/ or whatever class you wish to create nested in your main class...

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Move your public class to the top. In your case "public class approach" should be first.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Make your class public so that online compiler will access that class