All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
-
zyxw
- New poster
- Posts: 24
- Joined: Sat Mar 22, 2008 5:49 am
- Location: Chennai
-
Contact:
Post
by zyxw » Mon Jul 07, 2008 7:52 pm
Thanks once again
mf 
I'll follow them...
I am not totally useless, because I can still be used as a bad example

-
metalcarryon
- New poster
- Posts: 2
- Joined: Mon Feb 09, 2009 7:41 pm
Post
by metalcarryon » Mon Feb 09, 2009 7:48 pm
why WA?
Code: Select all
#include<stdio.h>
int main()
{
double a,b,c;
while(scanf("%lf %lf" ,&a ,&b)==2)
{
if(a>b)
{
c = a - b;
printf("%0.lf\n",c);
}
if(a<b)
{
c = (b - a);
printf("%0.lf\n",c);
}
}
return 0;
}
it returns 4294967296 on 4294967296 0 and vice-versa..
thanks!
-
Obaida
- A great helper
- Posts: 380
- Joined: Wed Jan 16, 2008 6:51 am
- Location: (BUBT) Dhaka,Bagladesh.
Post
by Obaida » Tue Feb 10, 2009 7:25 am
what will happen if a is equal to b?
I hope u better use long long.

try_try_try_try_&&&
_try@try.com
This may be the address of success.
-
asif_khan_ak_07
- New poster
- Posts: 25
- Joined: Fri Apr 17, 2009 8:24 am
Post
by asif_khan_ak_07 » Fri Apr 17, 2009 8:30 am
here is the code I wrote for problem 10055-Hasmat he brave warrior
#include<stdio.h>
int main()
{
int a,b,c;
while((scanf("%d %d",&a,&b)==2))
{
c=b-a;
if(c>0)
printf("%d\n",c);
else
printf("%d\n",-c);
}
return 0;
}
the sample input i provided yielded correct results. But when i sent the solution to Online Judge the reply was wrong answer. Is there any problem in the code? This is the first problem i tried sending to online judge. please help me.

-
mf
- Guru
- Posts: 1244
- Joined: Mon Feb 28, 2005 4:51 am
- Location: Zürich, Switzerland
-
Contact:
Post
by mf » Fri Apr 17, 2009 3:55 pm
Your program doesn't work, for example, for this input:
-
mf
- Guru
- Posts: 1244
- Joined: Mon Feb 28, 2005 4:51 am
- Location: Zürich, Switzerland
-
Contact:
Post
by mf » Fri Apr 17, 2009 9:08 pm
long long or double would work fine.
-
asif_khan_ak_07
- New poster
- Posts: 25
- Joined: Fri Apr 17, 2009 8:24 am
Post
by asif_khan_ak_07 » Sat Apr 18, 2009 6:35 pm
I used double and wrote the following code
#include<iostream.h>
int main()
{
double a,b,c;
while(cin>>a>>b)
{
c=a-b;
if(c>0)
cout<<c<<"\n";
else
cout<<-c<<"\n";
}
return 0;
}
but still the verdict from online judge is wrong answer
-
mf
- Guru
- Posts: 1244
- Joined: Mon Feb 28, 2005 4:51 am
- Location: Zürich, Switzerland
-
Contact:
Post
by mf » Sat Apr 18, 2009 8:31 pm
When a=b, your program now prints "-0".
And you shouldn't use iostream.h - it's been obsolete for many, many years. Replace it with:
Code: Select all
#include <iostream>
using namespace std;
-
mhn
- New poster
- Posts: 4
- Joined: Mon Jun 22, 2009 7:05 am
Post
by mhn » Mon Jun 22, 2009 9:29 am
m a beginner in acm..this is the first problem i m trying to solve ..nd having a lot of difficulties in understanding..watz wrong in my code..can anyone help me??
here's my code:
#include<stdio.h>
void main()
{
long long int i,j;
while(scanf("%lld %lld",&i,&j)==2)
{
if(i<j) printf("%lld\n",j-i);
else printf("%lld\n",i-j);
}
}
-
mf
- Guru
- Posts: 1244
- Joined: Mon Feb 28, 2005 4:51 am
- Location: Zürich, Switzerland
-
Contact:
Post
by mf » Tue Jun 23, 2009 8:32 am
Don't mutilate English words! That's just rude. And use [ code] [/code] tags to post code, or else it looks ugly.
main() must return 'int'. And this int should be 0.
If your compiler thinks "void main()" is okay, then you should really consider dumping it and get yourself a real compiler. For example, gcc (its windows ports are cygwin and mingw)
-
joshua.bender
- New poster
- Posts: 2
- Joined: Thu Sep 03, 2009 2:17 am
Post
by joshua.bender » Thu Sep 03, 2009 2:34 am
Can anybody help me what is wrong? i got the Wrong answer from the judge.
Code: Select all
import java.util.*;
public class Main {
public static void main(String args[]) {
long x, y;
Scanner scan = new Scanner(System.in);
String line = scan.nextLine();
Scanner scan2 = new Scanner(line);
scan2.useDelimiter(" ");
x = scan2.nextLong();
y = scan2.nextLong();
System.out.println((int) Math.abs(y - x));
}
}
-
Chaseph
- New poster
- Posts: 1
- Joined: Mon Nov 16, 2009 9:27 am
Post
by Chaseph » Mon Nov 16, 2009 9:29 am
Can someone tell me why my code is getting a wrong answer please. I've been having so much trouble with this being my first problem I just need a nudge to get me off the ground.
Code: Select all
import java.util.*;
import java.io.*;
class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true)
{
String line = reader.readLine();
if (line == null) break;
StringTokenizer tokenizer = new StringTokenizer(line);
long num1 = Long.parseLong(tokenizer.nextToken());
long num2 = Long.parseLong(tokenizer.nextToken());
System.out.println(num2 - num1);
}
}
}
-
pooanaji
- New poster
- Posts: 1
- Joined: Thu May 06, 2010 8:33 pm
- Location: India
Post
by pooanaji » Thu May 06, 2010 9:59 pm
Hi,
I solved the problem using cin and cout. The running time was 0.340. What can i do to improve my running time? Any ideas?
Cheers,
Pooja
-
sohel
- Guru
- Posts: 856
- Joined: Thu Jan 30, 2003 5:50 am
- Location: New York
Post
by sohel » Fri May 07, 2010 2:02 pm
use scanf() and printf()