10783 - Odd Sum

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Mamet
New poster
Posts: 7
Joined: Tue Mar 14, 2006 12:59 am

10783 - Odd Sum

Post by Mamet » Thu Apr 06, 2006 1:45 am

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;
}

kryptolus
New poster
Posts: 16
Joined: Sun Mar 19, 2006 9:36 am
Location: New York

Post by kryptolus » Thu Apr 06, 2006 1:58 am

Try entering an even number for a... You shouldn't limit yourself to the testcases in the problem.

Mamet
New poster
Posts: 7
Joined: Tue Mar 14, 2006 12:59 am

Post by Mamet » Thu Apr 06, 2006 2:44 am

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.

toni
New poster
Posts: 7
Joined: Wed Jul 25, 2007 6:03 pm

Post by toni » Mon Aug 20, 2007 5:09 pm

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 :)
Last edited by toni on Tue Aug 21, 2007 6:02 pm, edited 1 time in total.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Mon Aug 20, 2007 10:41 pm

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.

toni
New poster
Posts: 7
Joined: Wed Jul 25, 2007 6:03 pm

Post by toni » Tue Aug 21, 2007 5:55 pm

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.

WAandAC
New poster
Posts: 4
Joined: Sat Nov 03, 2007 4:32 am

Why WA

Post by WAandAC » Sat Nov 03, 2007 4:46 am

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.

S.M.ferdous
New poster
Posts: 13
Joined: Fri Nov 03, 2006 2:53 pm
Location: bangladesh
Contact:

Post by S.M.ferdous » Wed Nov 14, 2007 5:50 pm

It may be late.
std::cout <<"Case " << i+1 << ": " << calc (first, second)<<endl;


put an endline here also.

S.M.Ferdous

User avatar
theharshest
New poster
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

WA

Post by theharshest » Thu Feb 21, 2008 8:44 pm

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...
"if u r goin thru hell, keep goin"

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: WA

Post by mf » Thu Feb 21, 2008 9:09 pm

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.

User avatar
theharshest
New poster
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

@mf

Post by theharshest » Thu Feb 21, 2008 10:23 pm

changed the code....

but still getting WA :(

Code: Select all

deleted after AC
Last edited by theharshest on Thu Feb 21, 2008 11:10 pm, edited 2 times in total.
"if u r goin thru hell, keep goin"

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Thu Feb 21, 2008 10:44 pm

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.

User avatar
theharshest
New poster
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

@mf

Post by theharshest » Thu Feb 21, 2008 11:09 pm

thanks...
finally got AC....
:)
"if u r goin thru hell, keep goin"

wayne_911
New poster
Posts: 4
Joined: Thu Jun 25, 2009 10:02 am

Always get WA...Help comment on code pls

Post by wayne_911 » Thu Jun 25, 2009 10:10 am

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;
}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 10783 - Odd Sum

Post by mf » Thu Jun 25, 2009 12:48 pm

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.

Post Reply

Return to “Volume 107 (10700-10799)”