## 10963 - The Swallowing Ground

Moderator: Board moderators

salous
New poster
Posts: 1
Joined: Tue Dec 11, 2007 6:40 am

### I have problems with this one too

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

``````

jurajz
Learning poster
Posts: 69
Joined: Sat Sep 02, 2006 7:30 pm
Location: Slovakia
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

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

### Re: 10963 - The Swallowing Ground

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.
Have you ever...
• Wanted to work at best companies?
• Struggled with interview problems that could be solved in 15 minutes?
• Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

### Re: 10963 - The Swallowing Ground

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10963 - The Swallowing Ground

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

### Re: 10963 - The Swallowing Ground

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10963 - The Swallowing Ground

Don't print a blank line at the start of the output.
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

### Re: 10963 - The Swallowing Ground

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...

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10963 - The Swallowing Ground

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
``````
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

### Re: 10963 - The Swallowing Ground

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10963 - The Swallowing Ground

You need to reset flag to false at the start of each test case.
Check input and AC output for thousands of problems on uDebug!

Samleo
New poster
Posts: 11
Joined: Mon Dec 03, 2012 2:39 pm

### Re: 10963 - The Swallowing Ground

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
Last edited by Samleo on Sun Nov 03, 2013 4:39 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10963 - The Swallowing Ground

Either don't use abs or make your abs function return something.
Check input and AC output for thousands of problems on uDebug!

Samleo
New poster
Posts: 11
Joined: Mon Dec 03, 2012 2:39 pm

### Re: 10963 - The Swallowing Ground

brianfry713 wrote:Either don't use abs or make your abs function return something.
Thanks Solved with that tip Stupid mistake

NickStern
New poster
Posts: 3
Joined: Wed Nov 20, 2013 1:29 am

### Re: 10963 - The Swallowing Ground

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
``````
Last edited by NickStern on Thu Nov 21, 2013 6:39 am, edited 1 time in total.