Page 2 of 4

I have problems with this one too

Posted: Tue Dec 11, 2007 6:46 am
by salous
Can someone please help me with this problem? This should be a very easy one but I just don't understand why can't I get it right, I have read all the threads about this problem and tried lots of attempts but still no luck. Can you please help me point out what's wrong with my code? Thanks a lot!

Code: Select all


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

int main(void) {
	int dataNum = 0;
	scanf("%d", &dataNum);
	int i = 0;
	for(i = 0; i < dataNum; ++i) {
		int columnNum = 0;
		scanf("%d", &columnNum);
		int ableToFix = 1;
		if(columnNum < 0)
			ableToFix = -1;
		int diff = -1;
		int j = 0;
		for(j = 0; j < columnNum; ++j) {
			int y1, y2;
			y1 = y2 = 0;
			scanf("%d%d", &y1, &y2);
			if(ableToFix == 1) {
				int diffTemp = abs(y1 - y2);
				if(diff == -1)
					diff = diffTemp;
				else if(diff != diffTemp)
					ableToFix = -1;
			}
		}
		if(ableToFix == 1)
			printf("yes\n\n");
		else
			printf("no\n\n");
	}
}


Posted: Thu Dec 20, 2007 11:57 pm
by jurajz
Hi salous!

I solved this problem in the same way, as you, and I have AC. I think, that I found your little mistake. In new system, if you print extra blank line, the judge will give probably WA instead PE. I wrote about this in this thread:

http://online-judge.uva.es/board/viewtopic.php?t=22134

For this problem, the problem description says:
The outputs of two consecutive cases will be separated by a blank line.
And there is probably a mistake in your code, consecutive means, that blank line is "After each test case except last" or "Before each test case except first". And you write a blank line after each test case, including the last. Make something with this and I hope, that you will get AC ;)

Re: 10963 - The Swallowing Ground

Posted: Tue Mar 15, 2011 10:07 pm
by DD
In this problem, you can assume that the row of the northern block is bigger than the row of the southern block. Of course you also need to take care about the multi-case input.

Re: 10963 - The Swallowing Ground

Posted: Tue Sep 10, 2013 12:09 pm
by f.maru
can sb help me i get Wa

Code: Select all

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,y1,y2,q,tes;
    bool flag=false;
    cin>>tes;
    int ms;
    for(int j=2;j<=tes;j++)
    {
    cout<<endl;
    cin>>n;
    for(int t=1;t<=n;t++)
    {
     
            cin>>y1>>y2;
            q=abs(y1-y2);
            if (t==1)
            ms=q;
            if (q!=ms)flag=true;
    }
    if(flag==true)cout<<"no"<<endl;
    else
    cout<<"yes"<<endl;
}
}

Re: 10963 - The Swallowing Ground

Posted: Wed Sep 11, 2013 12:17 am
by brianfry713
Try running your code on the sample input.

Re: 10963 - The Swallowing Ground

Posted: Wed Sep 11, 2013 3:18 pm
by f.maru
i tried sample and i got correct answer
this is my new code i still don't know what to do if someone can help me

Code: Select all

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,y1,y2,q,tes;
    bool flag=false;
    cin>>tes;
    int ms;
    for(int j=1;j<=tes;j++)
    {
    cout<<endl;
    cin>>n;
    for(int t=1;t<=n;t++)
    {
     
            cin>>y1>>y2;
            q=y1-y2;
            if (t==1)
            ms=q;
            if (q!=ms)flag=true;
    }
    if(j>1)
    cout<<endl;
    if(flag==true)cout<<"no"<<endl;
    else
    cout<<"yes"<<endl;
}
}

Re: 10963 - The Swallowing Ground

Posted: Wed Sep 11, 2013 10:08 pm
by brianfry713
Don't print a blank line at the start of the output.

Re: 10963 - The Swallowing Ground

Posted: Wed Sep 11, 2013 11:52 pm
by f.maru
You ean don't use cout<<endl before cin>>n in the for?
I tried this but I got WA.
And I think I have to seperate output with bank line except first output like leap year...

Re: 10963 - The Swallowing Ground

Posted: Thu Sep 12, 2013 10:43 pm
by brianfry713
The outputs of two consecutive cases will be separated by a blank line.
Input:

Code: Select all

2

5
2 1
0 -1
1 0
1 0
2 1

5
2 1
0 -1
1 0
1 0
2 1
Correct output:

Code: Select all

yes

yes

Re: 10963 - The Swallowing Ground

Posted: Thu Sep 12, 2013 11:09 pm
by f.maru
Sry but I had submitted my code without printing blank line befor reading n but I got WA and it the output is same as what wrote

Code: Select all

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,y1,y2,q,tes;
    bool flag=false;
    cin>>tes;
    int ms;
    for(int j=1;j<=tes;j++)
    {
    cin>>n;
    for(int t=1;t<=n;t++)
    {
     
            cin>>y1>>y2;
            q=y1-y2;
            if (t==1)
            ms=q;
            if (q!=ms)flag=true;
    }
    if(j>1)
    cout<<endl;
    if(flag==true)cout<<"no"<<endl;
    else
    cout<<"yes"<<endl;
}
}

Re: 10963 - The Swallowing Ground

Posted: Fri Sep 13, 2013 10:16 pm
by brianfry713
You need to reset flag to false at the start of each test case.

Re: 10963 - The Swallowing Ground

Posted: Tue Oct 22, 2013 12:56 pm
by Samleo
Why is my code getting WA? I am printing the lines properly, have passed all test inputs on the forum.. But still WA :(

Code: Select all

CODE REMOVED AFTER AC
Would appreciate some help and test inputs :)
Thanks,
Sam

Re: 10963 - The Swallowing Ground

Posted: Tue Oct 22, 2013 10:35 pm
by brianfry713
Either don't use abs or make your abs function return something.

Re: 10963 - The Swallowing Ground

Posted: Sun Nov 03, 2013 4:39 pm
by Samleo
brianfry713 wrote:Either don't use abs or make your abs function return something.
Thanks :) Solved with that tip :D Stupid mistake

Re: 10963 - The Swallowing Ground

Posted: Wed Nov 20, 2013 1:47 am
by NickStern
I keep getting WA for this problem but it responds fine to all the test cases I have given it. Could someone tell me the issue with my code? Unlike most of the other posts it is in java.

Code: Select all

Issue resolved