Formatted Numbers

Press the key above the tab button 3 time to produce this character(s), ```.
This character is called Grave Accent.
Then write language code (cpp, c, python, rb, java, bash etc.)
Write your code.
Then type three grave accents ```again like this,

```python
print("something")
```

and the result will be like this,

print("something")

Try to edit your code(s) with this now. Formatted codes are easier to be read then unformatted ones. They also looks cool.

a = input()
b = len(a)
c = b // 3
d = b % 3
if d > 0 and b > 3:
    print(a[:d], end=",")
    for i in range(c - 1):
        print(a[(b // c) * i + d:(b // c) * (i + 1) + d], end=",")
    print(a[-3:])
elif b < 4:
    print(a)
else:
    for i in range(c - 1):
        print(a[(b // c) * i:(b // c) * (i + 1)], end=",")
    print(a[-3:])

Sorry I gave wrong indentation in print statement.

Now, please correctly format it;
for example:

if d > 0 and b > 3:
print(a[:d], end=",")

should be,

if d > 0 and b > 3:
    print(a[:d], end=",")

code:

```
if d > 0 and b > 3:
    print(a[:d], end=",")
```

and this also.

And you don’t need to create new posts. Just edit previous ones.

Bro I reformated it. So plz help now

Showing wrong ans in 4th no. test case.Plz help
#include <stdio.h>
int main()
{
long long int A;
scanf(“%lld”,&A);
int r,i=0,a[100],j;
while(A!=0)
{
r=A%1000;
a[i++]=r;
A/=1000;
}
for(j=i-1;j>=0;j–)
{

while(a[j]!=a[0])
{
    printf("%lld,",a[j]);
     a[j--];
}
if(a[j]==a[0])
     printf("%lld",a[0]);

}

return 0;
}

Yes, Sorry. But I was Just teaching you code formatting. Cause I couldn’t understand your code.

However, here is the reason of your code being rejected. For big numbers such as this,

2389346234712562489

the output becomes something like this,

2,389,489
346,489
234,489
712,489
562,489

Its seems like your code is printing the last part over and over cause you have put it inside the loop.
Just bring it outside of the loop just like this and your code should be accepted.

for i in range(c - 1):
    print(a[(b // c) * i + d:(b // c) * (i + 1) + d], end=",")
    print(a[-3:]) #bring this line out of the loop

and after fixing it, see this also,

1
12
123
1,234
12,345
123,456
1,234,567
12,3456,678 // what ?
123,456,789
1,234,567,890

And it seems your code is giving WA for inputs lenght 9. find out the reason and fox it also.

And again, you have not edited this post yet. please do so.

Please format and edit your code using this method.

Dear elders ,what is the problem in my code?
#include<stdio.h>
#define M(K3,N) (K3=N%1000)
#define L(K2,N) (K2=N%1000)
#define O(K1,N) (K1=N%1000000)
int main()
{
int N,K1,K2,K3,M,O;
scanf(“%d”,&N);
if(N < 200000000){
M(K3,N);
N=N/1000;
L(K2,N);
N=N/1000;
O(K1,N);

    printf("%d,%d,%d",K1,K2,K3);
}

}

Please format your code properly before posting on Toph. You can use this as a reference.

And the output of your code should be like this. That is the problem.

I think toph authority should give the opportunity to see the test cases, like codeforces.
In codeforces we can see the test case where we get wrong answer.

Well, its because there is deference how both sites introduce themselves.

cf is basically known as a platform where contest programmers can prove themselves when Toph declares themselves as a sports programming platform. cf has to keep holding contests constantly because of how they are known and thus test cases after contests don’t hold that importance to them. Thus, showing test cases after a contest becomes a feature.

However in case of Toph, the sponsored contests they hold to run the site, in case of most of them being held onsite and many of them being a process of some kind of selection, it is important to hide test cases to avoid conflicts regarding a contest after its ending.

That’s the reason if your concern is about contests.

However in case of the problems that you can solve any time from problems library, the practice of revealing the test cases in even more scarce. If test cases are revealed, people might find leeways for a problem that they should not find and thus the online judges do not usually reveal their test cases. Your solution should be enough for tacking any kind of situations stated in the problem statements and inside the given constraints and thus the revelation of the test cases are thought to bis considered unnecessary.

by the way that is what I think about this matter. What is your official opinion @hjr265.
[dark side of touhid: hehe, let’s involve a moderator in this conversation.]

Where is my error?!

public static void main(String[]args){
Scanner input=new Scanner(System.in);
int A=input.nextInt();
if(A>=0 && A<200000000){
if(A<1000){
System.out.println(A);
}
int A1=0;
int At=0;
int A2=0;
int At2=0;
if(A>=1000 && A<1000000){
A1=A%1000;
At=A/1000;
System.out.println(At+“,”+A1);
}
if(A>=1000000){
A1=A%1000;
At=A/1000;
A2=At%1000;
At2=At/1000;
System.out.println(At2+“,”+A2+“,”+A1);
}
}
}
}

My code is giving desired answer. But judge is saying it wrong. why?
S = input()
n = len(S)+1
li = list()
for i in range(-1, -n, -1):
if i in [-4,-7,-10]:
li.append(“,”)
li.append(S[i])
li.reverse()
print()
print(“”.join(li))

#include<stdio.h>
int main()
{
    int A,b,c,d;
    scanf("%d",&A);
     if(0 <= A < 200000000) {
             b=A%1000;
             b=A%1000;
             A=A/1000;
             c=A%1000;
             A=A/1000;
             d=A%1000;
            printf("%d,%d,%d",d,c,b);
        }
    return 0;
}

tell me the problem of my code, prblm: wrong result

  Scanner input=new Scanner(System.in);
        int A,b,c,d;
        A=input.nextInt();
        if(A < 200000000) {
              b=A%1000;
               A=A/1000;
               c=A%1000;
               A=A/1000;
             d=A%1000;
             if(c==0){
                 System.out.println(b);
             }
             else if(d==0){
                 System.out.println(c+","+b);
             }else{
                 System.out.println(d+","+c+","+b);
             }
             
        }   

please tell me the problem in this code , judges give me wrong ans

My personal solution that works:

#include <stdio.h>

int main() {
int i,a,count=0,num[1000];
scanf(“%d”,&a);

if(0<=a && a<100)
	printf("%d",a);
else
{for(i=0;a!=0;i++)
{
	num[i]=a%1000;
	a=a/1000;
	count++;
}

printf("%d,",num[count-1]);
for(i=count-2;i>0;i--)
{if (0<=num[i] && num[i]<10)
  printf("00%d,",num[i]);
 
 else if(10<=num[i] && num[i]<100)
  printf("0%d,",num[i]);
 
 else printf("%d,",num[i]);
}
if (0<=num[0] && num[0]<10)
  printf("00%d",num[0]);
 
 else if(10<=num[0] && num[0]<100)
  printf("0%d",num[i]);
else
printf("%d",num[0]);}

return 0;

}

#include<stdio.h>
int main()
{
    int n,a1,a2,a3;
    scanf("%d",&n);
    a1=n%1000;
    n/=1000;
    a2=n%1000;
    n/=1000;
    a3=n%1000;
    n/=1000;
    printf("%d,%d,%d",a3,a2,a1);
    return 0;
}

in the fourth test , it says wrong answer …
what’s the problem here ?

@Farhan2500 try 1000 or numbers<10000 with your code…

2 Likes
import java.util.Scanner;
public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();
		
		if(A>0 && A<200000000){
			
			int num1 = A%1000;
			A= A/1000;
			
			int num2 = A%1000;
			A= A/1000;
			
			int num3 = A%1000;
			System.out.print(num3+","+num2+","+num1);
		}
	}
}

Can anyone tell me what’s the wrong in my program?

a=int(input())
if a//(10**9)!=0:
	print(str(a//(10**9)),str((a%(10**9))//(10**6)),str((a%(10**6))//1000),str(a%(10**3)),sep=",")
elif a//(10**6)!=0:
	print(str(a//(10**6)),str((a%(10**6))//1000),str(a%(10**3)),sep=",")
elif a//(10**3)!=0:
	print(str(a//1000),str(a%1000),sep=",")
else:
	print(a)

I wrote this using python 3.7.
when I test it it’s showing “1 Sample Passed”
but when I submit it’s showing wrong answer for 4th test case
Can anyone tell me what’s wrong here?