File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3131import java .io .*;
3232/* Name of the class has to be "Main" only if the class is public. */
3333class MagicalDoors
34- {
34+ { //Main Function
3535 public static void main (String [] args ) throws java .lang .Exception
3636 {
37- Scanner in = new Scanner (System .in );
38- int t = in .nextInt ();
39- while (t >0 )
37+ Scanner in = new Scanner (System .in ); //Scanner for taking input
38+ int t = in .nextInt (); //Variable t for no of test case
39+ while (t >0 ) //loop for every test case
4040 {
4141
42- StringBuilder str = new StringBuilder (in .next ());
43- long res = 0 ;
44- if (str .charAt (0 ) == '0' )
45- res ++;
46- for (int i = 1 ; i <str .length (); i ++)
42+ StringBuilder str = new StringBuilder (in .next ()); //Taking input int String builder str
43+ long res = 0 ; //Variabe of long type for storing result
44+ if (str .charAt (0 ) == '0' ) //checking the first character of the string (Whether it is 0 or 1)
45+ res ++; //if 0 then we are adding 1 to result
46+ for (int i = 1 ; i <str .length (); i ++) //for loop starting from 2nd character
4747 {
48- if (str .charAt (i ) != str .charAt (i -1 ))
49- res ++;
48+ if (str .charAt (i ) != str .charAt (i -1 )) //Checking that is the previous charcter same or not
49+ res ++; //if not same then adding 1 to result
5050 }
51- System .out .println (res );
52- t --;
51+ System .out .println (res ); //printing the result
52+ t --; //decrementing the value of t
5353 }
5454 }
5555}
You can’t perform that action at this time.
0 commit comments