Why my solution not working?

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
			BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
			PrintWriter out = new PrintWriter(System.out,true);
			StringTokenizer stz = new StringTokenizer(sc.readLine());
			int n = Integer.parseInt(stz.nextToken());
			int m = Integer.parseInt(stz.nextToken());
			String s = sc.readLine();
			while(m-->0){
                   stz = new StringTokenizer(sc.readLine());
                   int type = Integer.parseInt(stz.nextToken());
                   if(type == 2){
                   	int c = Integer.parseInt(stz.nextToken());
                   	int d = Integer.parseInt(stz.nextToken());
                   	String s1 = s.substring(c-1,d);
                   	int f =  Integer.valueOf(s1);
                   	int count = 0;
                   	for(int i =0;i<s1.length();i++){
                   		if(Integer.valueOf(s1.charAt(i))%3==0)
                   		count++;
                   		String s2 = "";
                   		s2+=s1.charAt(i);
                   		for(int j =i+1;j<s1.length();j++){
                   			s2+=s1.charAt(j);
                   			if(Integer.valueOf(s2)%3 == 0)
                   			count++;
                   		}
                   	}
                   	out.println(count);
                   	
                   }
                   else{
                   	int x = Integer.valueOf(stz.nextToken());
                   	int y = Integer.valueOf(stz.nextToken());
                   	StringBuilder u = new StringBuilder(s);
                   	u.replace(x-1,x,y+"");
                   	s = u.toString();
                   	}
			}
	}
}

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

/* Name of the class has to be “Main” only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out,true);
StringTokenizer stz = new StringTokenizer(sc.readLine());
int n = Integer.parseInt(stz.nextToken());
int m = Integer.parseInt(stz.nextToken());
String s = sc.readLine();
while(m–>0){
stz = new StringTokenizer(sc.readLine());
int type = Integer.parseInt(stz.nextToken());
if(type == 2){
int c = Integer.parseInt(stz.nextToken());
int d = Integer.parseInt(stz.nextToken());
String s1 = s.substring(c-1,d);
int f = Integer.valueOf(s1);
int count = 0;
for(int i =0;i<s1.length();i++){
if(Integer.valueOf(s1.charAt(i))%3==0)
count++;
String s2 = “”;
s2+=s1.charAt(i);
for(int j =i+1;j<s1.length();j++){
s2+=s1.charAt(j);
if(Integer.valueOf(s2)%3 == 0)
count++;
}
}
out.println(count);

               }
               else{
               	int x = Integer.valueOf(stz.nextToken());
               	int y = Integer.valueOf(stz.nextToken());
               	StringBuilder u = new StringBuilder(s);
               	u.replace(x-1,x,y+"");
               	s = u.toString();
               	}
		}
}

}

Probably,I would have helped you if you post the question in well indented way… Post again in good way.

@getsuga…please go through this…How to ask for help? - help - CodeChef Discuss

1 Like

You can always edit your question I believe, read please also what @kunal361 linked :wink: