10928 - My Dear Neighbours
Moderator: Board moderators
-
- Learning poster
- Posts: 70
- Joined: Sat Feb 05, 2005 9:38 am
- Location: Gurukul
Sorting isn't necessary, but the output has to be sorted. The most tricky part of this problem is reading the input data correctly. For each test case:
- get a line with P
- get P lines with the descriptions of neighborhoods
- find the index of the line that contains the least amount of numbers (if there are more possible answers, store all of them and output them in increasing order)
- output it
- if this is not the last test case, get a line (the empty line that separates test cases)
Check whether you don't have unnecessary whitespaces in your output.
Try the following test data:
The correct output:
There are no spaces after 2 and 10, there is an end-of-line character after both of them.
- get a line with P
- get P lines with the descriptions of neighborhoods
- find the index of the line that contains the least amount of numbers (if there are more possible answers, store all of them and output them in increasing order)
- output it
- if this is not the last test case, get a line (the empty line that separates test cases)
Check whether you don't have unnecessary whitespaces in your output.
Try the following test data:
Code: Select all
2
2
1
2
13
10 11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
1 2 3 4
1 2 3 4
1 2 3 4
Code: Select all
1 2
2 3 4 5 6 7 8 9 10
Last edited by misof on Thu Oct 20, 2005 11:28 pm, edited 1 time in total.
-
- Learning poster
- Posts: 81
- Joined: Wed May 09, 2007 9:59 pm
- Location: (CSE,DU) Dhaka,Bangladesh
488 WA,PLES HELP
here is sample input output: I got WA PLES help? Is there any special case?
input:
4
3
2
1 3
2 1
4
2
3
1 4 2
2 1 3
2
1
2
13
10 11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
1 2 3 4
1 2 3 4
1 2 3 4
output:
1
1 2
1 2
2 3 4 5 6 7 8 9 10
Press any key to continue
Re: 10928 - My Dear Neighbours
My code below is passing all the test cases mentioned in the thread but getting WA when submitted..
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int a[1000];
int main()
{
int n,p,d,i,min;
char str[1000];
cin>>n;
while (n-- != 0)
{
i = 0;
cin>>p;
min = p-1;
memset(a,0,sizeof(a));
while (p != 0)
{
fgets(str,999,stdin);
istringstream str1(str);
while (str1 >> d)
{
a++;
}
if (a != 0)
{
if (a < min)
{
min = a;
}
i++;
p--;
}
}
for (i=0;i<1000;i++)
{
if (a == min)
{
cout<<i+1<<" ";
}
}
cout<<endl;
}
return 0;
}
What is the mistake??
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int a[1000];
int main()
{
int n,p,d,i,min;
char str[1000];
cin>>n;
while (n-- != 0)
{
i = 0;
cin>>p;
min = p-1;
memset(a,0,sizeof(a));
while (p != 0)
{
fgets(str,999,stdin);
istringstream str1(str);
while (str1 >> d)
{
a++;
}
if (a != 0)
{
if (a < min)
{
min = a;
}
i++;
p--;
}
}
for (i=0;i<1000;i++)
{
if (a == min)
{
cout<<i+1<<" ";
}
}
cout<<endl;
}
return 0;
}
What is the mistake??
Re: 10928 - My Dear Neighbours
I'm getting WA in this problem
Please give some I/O.
Thank's in advance.
Please give some I/O.
Code: Select all
Got Acc ...
Re: 10928 - My Dear Neighbours
Ok forget that. Got AC. But one thing...
for misof's input
output will be,
So just a newline '\n' (not a blank line) after every case including the last one.
for misof's input
Code: Select all
2
2
1
2
13
10 11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
11 12 13
1 2 3 4
1 2 3 4
1 2 3 4
Code: Select all
1 2
2 3 4 5 6 7 8 9 10
-
- Experienced poster
- Posts: 147
- Joined: Mon Jun 07, 2010 11:43 am
- Location: University Of Dhaka,Bangladesh
- Contact:
Re: 10928 - My Dear Neighbours
Too easy a problem. Dont need to make the thinks complex,just count inputs in every line,index them and find out the lowes value. then print the ouputs.
Only one space will separate the outputs,which makes the problem even more easier.
if you still get wa,check this IO:
Output from my ac code:
Only one space will separate the outputs,which makes the problem even more easier.
if you still get wa,check this IO:
Code: Select all
2
8
2
4 3
1 2 3
2 1 3 4
1 2 3 4 5
5 3 1 3 5
2
5
12
11 10 9
1 2 3
1 2 3 4
5 6 7 8
4 3 1 2
11 9 3
1 2 3 4 5 6 7 8 9
1 2 10 9 8 7
1 2 3 4
6 7 8
5 4 3
1 2 3 4 5
Code: Select all
1 7 8
1 2 6 10 11
UVa stats: http://felix-halim.net/uva/hunting.php?id=63448
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
-
- Experienced poster
- Posts: 145
- Joined: Thu Aug 14, 2003 8:42 am
- Location: Mountain View, California
- Contact:
Re: 10928 - My Dear Neighbours
sharath wrote:My code below is passing all the test cases mentioned in the thread but getting WA when submitted..
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int a[1000];
int main()
{
int n,p,d,i,min;
char str[1000];
cin>>n;
while (n-- != 0)
{
i = 0;
cin>>p;
min = p-1;
memset(a,0,sizeof(a));
while (p != 0)
{
fgets(str,999,stdin);
istringstream str1(str);
while (str1 >> d)
{
a++;
}
if (a != 0)
{
if (a < min)
{
min = a;
}
i++;
p--;
}
}
for (i=0;i<1000;i++)
{
if (a == min)
{
cout<<i+1<<" ";
}
}
cout<<endl;
}
return 0;
}
What is the mistake??
The size of str is not enough. The number of neighbors in this problem will not exceed 1000 but the length of each line may exceed. You should get A.C. once you enlarge the length of str.
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?
misof wrote:Sorting isn't necessary, but the output has to be sorted. The most tricky part of this problem is reading the input data correctly. For each test case:
- get a line with P
- get P lines with the descriptions of neighborhoods
- find the index of the line that contains the least amount of numbers (if there are more possible answers, store all of them and output them in increasing order)
- output it
if this is not the last test case, get a line (the empty line that separates test cases)[/even for the last test case you have 2 print a new line all u have 2 worry about is whitespaces]
Check whether you don't have unnecessary whitespaces in your output.
Try the following test data:The correct output:Code: Select all
2 2 1 2 13 10 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13 1 2 3 4 1 2 3 4 1 2 3 4
There are no spaces after 2 and 10, there is an end-of-line character after both of them.Code: Select all
1 2 2 3 4 5 6 7 8 9 10
Re: 10928 - My Dear Neighbours
Runtime Error on my following code. Can someone tell me why?
AC'ed
AC'ed
Last edited by moxlotus on Thu Dec 04, 2014 8:05 pm, edited 1 time in total.
Re: 10928 - My Dear Neighbours
Increase array limit
It must be
You will get PE. Don't print extra space after last number.
Don't forget to remove your code after getting accepted.
Code: Select all
char *str = new char[size];
Code: Select all
char *str = new char[size + 1];
Don't forget to remove your code after getting accepted.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman