Problem Code: TWOSTR

my code is working fine and giving the desired output in my eclipse but not getting accepted. Can sm1 plz point out the error.
/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class WildcardMatching {
public static void main(String[] args) throws java.lang.Exception {
try {
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
int t = sc.read() - ‘0’;
sc.readLine();
while (t-- > 0) {
String firstString = sc.readLine();
String secondString = sc.readLine();
int length = firstString.length();
for (int i = 0; i < length; i++) {
if (firstString.charAt(i) != secondString.charAt(i) ) {

                    if (firstString.charAt(i)!= '?' && secondString.charAt(i) != '?') {
                        //System.out.println(firstString.charAt(i) );
                       // System.out.println(secondString.charAt(i) );
                        System.out.println("No");
                        break;
                    }
                }
                if (i == (length - 1)) {
                    System.out.println("Yes");
                }
            }
        }


    } catch (Exception e) {
    }
}

}

I’m not familiar with Java, but is your code able to read in T correctly if T >= 10?

I tried to debug my code according to your suggestion and yes my code is not working for T>10. I gave input 11 for T but its showing 1.if you have any more suggestions or if you tell how can I take correct integer input through read() or should I simply use scanner instead of buffer.
thank you :slight_smile:

I don’t know what the best practice for Java is (perhaps a Java person could weigh in … ?) but this seems to work:

            int t = Integer.parseInt(sc.readLine());

Edit:

A random sampling of AC Java solutions suggests that people prefer to use Scanner :slight_smile:

Thank you.
I would be more careful from now on while using bufferedReader.
my code is accepted, thank you :smile:

1 Like