Page 1 of 3

10783 - Odd Sum

Posted: Thu Apr 06, 2006 1:45 am
by Mamet
I am trying to solve this so easy problem but I keep getting wrong answer. plz can someone tell me why?? Thx!

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main()
{
  long t, a,b,c=0,r;
  scanf("%d",&t);
  while (t>0){
  c++;
  scanf("%d", &a);
  scanf("%d", &b);
  /*r=(1+(b-a)/2)*((a+b)/2);*/
  r=0;
  while (a<=b){
  r+=a;
  a+=2;
  }
  printf("Case %d: %d\n", c, r);
  t--;
  }

  return 0;
}

Posted: Thu Apr 06, 2006 1:58 am
by kryptolus
Try entering an even number for a... You shouldn't limit yourself to the testcases in the problem.

Posted: Thu Apr 06, 2006 2:44 am
by Mamet
Oh thx sorry I read wrong the problem. I didn't look i was looking only for the odd terms :P . thx a lot. I got AC now.

Posted: Mon Aug 20, 2007 5:09 pm
by toni

Code: Select all

 
code removed  
hello everybody , i have no idea about why this code got WA.
I use the formula to solve the question.
I have try many case but cannot figured out why?
can any one help me ?
thanks :)

Posted: Mon Aug 20, 2007 10:41 pm
by mf
toni wrote:I have try many case but cannot figured out why?
Oh really?
It doesn't even pass the sample input/output. Here's a hint: your program's output is compared byte-wise with the correct output, and even a single mismatch (e.g. in case numbering) will lead to a WA (or PE) verdict.

Posted: Tue Aug 21, 2007 5:55 pm
by toni
toni wrote:

Code: Select all

/* 
   code remove.
hello everybody , i have no idea about why this code got WA.
I use the formula to solve the question.
I have try many case but cannot figured out why?
can any one help me ?
thanks :)
i fell really embarrassed, thanks mf so much :D
i didn't take notice that i have changed my code.

Why WA

Posted: Sat Nov 03, 2007 4:46 am
by WAandAC
Hi,

I know this is an easy problem, but why I get WA?

I tested the even number case, but is there anything wrong with output or tricky test cases?

Code: Select all

#include <iostream>
#include <string>

int calc (int a, int b)
{
	if ( a == b && a%2 == 0 && b % 2 == 0)
	{
		return 0;
	}
	int low = a;
	int high = b;

	if (a > b)
	{
		low = b;
		high = a;
	}

	

	if ( 0 == low % 2)
	{
		low++;
	}

	if ( 0 == high % 2)
	{
		high--;
	}

	return (high + low) / 2 * (((high - low)/2) + 1);

	
}

int main ()
{
	int caseNum = 0;
	int first = 0;
	int second = 0;
	while (true)
	{
		std::cin >> caseNum;
		for (int i = 0; i < caseNum; i++)
		{
			std::cin >> first >> second;
			if ( i == caseNum - 1)
			{
				std::cout <<"Case " << i+1 << ": "  << calc (first, second);
			}else{
				std::cout <<"Case " << i+1 << ": "  << calc (first, second) <<std::endl;
			}
			 
		}
		if (std::cin.eof())
		{
			break;
		}
	}
	return 0;
}

Thank you.

Posted: Wed Nov 14, 2007 5:50 pm
by S.M.ferdous
It may be late.
std::cout <<"Case " << i+1 << ": " << calc (first, second)<<endl;


put an endline here also.

S.M.Ferdous

WA

Posted: Thu Feb 21, 2008 8:44 pm
by theharshest
getting WA for this code---
:(

#include<iostream>

using namespace std;

int sum(int,int);
int main()
{
int n,i,k=0,s,x,y,j;

while(cin>>n)
{
k++;
for(i=0;i<n;i++)
{
cin>>x>>y;
s=sum(x,y);
cout<<"Case "<<k<<": "<<s<<endl;
}
}

}

int sum(int x, int y)
{
int dif=y-x;
int t=0;

if(x==y)
{
if(x%2==0)
return 0;
else
return x;
}
if(x%2==0 && y%2==0)
{
return ((y-x)/2+1)*(x+1) + ((y-x)/2)*(((y-x)/2)-1);
}
if(x%2==0 && y%2!=0)
{
return ((y-x)/2+1)*(x+1) + (((y-x)/2)+1)*(y-x)/2;
}
if(x%2!=0 && y%2!=0)
{
return ((y-x)/2+1)*(x) + (((y-x)/2)+1)*(y-x)/2;
}
if(x%2!=0 && y%2==0)
{
return ((y-x)/2+1)*(x) + (((y-x)/2)+1)*(y-x)/2;
}

}


plz help.....
tx in anticipation...

Re: WA

Posted: Thu Feb 21, 2008 9:09 pm
by mf
theharshest wrote:getting WA for this code---
There's sample input/output in the problem statement, and your code doesn't pass it. (one byte is wrong)
So what other outcome could you have possibly expected?

And please, use phpbb's [ code] tags for code and proper English spelling next time when you ask for help.

@mf

Posted: Thu Feb 21, 2008 10:23 pm
by theharshest
changed the code....

but still getting WA :(

Code: Select all

deleted after AC

Posted: Thu Feb 21, 2008 10:44 pm
by mf
Input:

Code: Select all

4
1 100
2 100
1 99
2 99
The correct output for this input is:

Code: Select all

Case 1: 2500
Case 2: 2499
Case 3: 2500
Case 4: 2499
You don't need any complicated formulas for this problem. Keep it simple - a dumb one-line for-loop is all that you need for this problem.

@mf

Posted: Thu Feb 21, 2008 11:09 pm
by theharshest
thanks...
finally got AC....
:)

Always get WA...Help comment on code pls

Posted: Thu Jun 25, 2009 10:10 am
by wayne_911
I am a newbie to uva judge online website..I am still not very sure how the format of the code should be..So far, i seem get reply none other than WA.... So i try on this simple question...which also give me WA as well. Can anyone pls comment on my code? Thx..

Code: Select all

#include <iostream>
using namespace std;

int main()
{
	int a,b;
	int total=0;

	cout<<"input: ";
	cin>>a;
	cin>>b;

	for(int i=a; i<=b; i++)
		if(i%2)
			total+=i;

	cout<<"output: "<<total<<endl;

	return 0;
}

Re: 10783 - Odd Sum

Posted: Thu Jun 25, 2009 12:48 pm
by mf
There are just three simple rules:

1) Follow the output format specification exactly, don't output anything extra, like "input: " or "output: ". Judge is only a dumb robot who compares output files byte-wise, and those words don't make much sense to it.

Instead of "output: ", you're supposed to print "Case 1: ", "Case 2: ", etc. in this particular problem.

2) Follow the input format specification exactly.
The first line of input gives you the number of test cases, T.
Then T test cases follow. Each test case consists of 2 integers a and b in two separate lines.
Your program must process all the test cases present in the input.

3) Solve the problem correctly, within its time and memory limits. Your program looks good here.