Moderator: Board moderators

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### Re: 111 Why WA??

Would someone please tell me how to take input for this problem?
How to check end of input for this problem after taking integer n?

tryit1
Experienced poster
Posts: 119
Joined: Sun Aug 24, 2008 9:09 pm

### Re: 111 Why WA??

lnr wrote:Would someone please tell me how to take input for this problem?
How to check end of input for this problem after taking integer n?

Code: Select all

`````` n= read first integer
for(j=0;j<n;j++) { read the ranking into an array; }

for(i=0;i<n-1;i++) {
for(k=0;k<n;k++) { read the sequence into array }
}
``````

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### Re: 111 Why WA??

tryit1 wrote:
lnr wrote:Would someone please tell me how to take input for this problem?
How to check end of input for this problem after taking integer n?

Code: Select all

`````` n= read first integer
for(j=0;j<n;j++) { read the ranking into an array; }

for(i=0;i<n-1;i++) {
for(k=0;k<n;k++) { read the sequence into array }
}
``````
May be you are wrong.
In the problem the input was like this:
10
3 1 2 4 9 5 10 6 8 7
1 2 3 4 5 6 7 8 9 10
4 7 2 3 10 6 9 1 5 8
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6

Here n=10
And there are five rows.

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### 111 History Grading Runtime error

Code removed.
Last edited by lnr on Sun Jan 04, 2009 2:08 pm, edited 1 time in total.

newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

### Re: 111 History Grading Runtime error

your code doesnt get RTE. The judge just simply replies WA..
Few things:
1. You actually dont need to read the line in string and then process to integers. what if there are tabs/more than one spaces to separate them?
2. i didnt get why you did m = _index-1, for LCS the for loops runs from 1 to arraylength.. (wait i get it now.. your _index starts from 1)
hmm..

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### Re: 111 Why WA??

Code removed.
Last edited by lnr on Sat Jan 31, 2009 9:17 am, edited 1 time in total.

newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

### Re: 111 Why WA??

@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
hmm..

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### Re: 111 Why WA??

newkid wrote:@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
I modified my input taking code.
This time I used "strtok(char *)" function and got accepted.

Many thanks for your reply because your input taking code was better, (no need to cast the string to integer).

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

### Re: 111 Why WA??

Code: Select all

``````deleted after AC..
``````
Last edited by theharshest on Wed Feb 04, 2009 10:49 pm, edited 1 time in total.
"if u r goin thru hell, keep goin"

newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

### Re: 111 Why WA??

I think the culprit line is

Code: Select all

``str1.resize(tmp.length()/2);``
why? cause the problem statement says there might be 'one or more spaces' between two integers. so for input line like "1<10 spaces>2<10 spaces>3" your will resize to (20+3)/2 = 11. thus your str1.size() will return 11 which you have used in mat[str2.size()][str1.size()].

Anyway you already know the size of the vector, right? its 'n'. so use the following instead

Code: Select all

``str1.resize(n);``
Further, you don't need the matrix size to be 1010.. just make it 32 (problem statement says n <= 20)
And

Code: Select all

``````      for(int i=0;i<=str1.size();i++)
mat[0][i]=0;

for(int i=0;i<=str2.size();i++)
mat[i][0]=0;``````
these lines are redundant as you already set it to zero using memset.

another note..

Code: Select all

``````  else
mat[i][j]=max(mat[i-1][j],mat[i][j-1]);;``````
try to avoid this kind of bug.. two semicolons. Its not a problem in this code but believe me when this happens its really hard to find and fix.
hmm..

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

### Re: 111 Why WA??

Thanks newkid..

I got AC
"if u r goin thru hell, keep goin"

asqwzxdfercv
New poster
Posts: 3
Joined: Sat May 16, 2009 3:40 am

### Re: 111 Why WA??

lnr wrote:
newkid wrote:@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
I modified my input taking code.
This time I used "strtok(char *)" function and got accepted.

Many thanks for your reply because your input taking code was better, (no need to cast the string to integer).
I also got problem in my input
The problem is, if the last sequence ends in space(' '), !cin.eof() is true so an extra line is outputed.
How should I modify my code?
btw, how do ppl get 0.000 runtime for their codes? My fastest program in #10038(ugly number) takes even 0.008s to just cout a line

Code: Select all

``manage to solve with stupid method :(``

valkov
New poster
Posts: 20
Joined: Tue Jul 20, 2010 3:11 pm

### Re: 111 Why WA??

Just got AC. So for those of you who are having trouble reading the input and do not care particularly about the speed of it:

Code: Select all

``````    cin >> n;
unsigned t;

for(unsigned i = 0; i < n; i++) {
cin >> t;
a[t] = i;
}
while(true) {
for(unsigned i = 0; i < n; i++) {
if(!(cin >> t)) {
return 0;
}
b[t] = i;
}
cout << call your function in order to solve the problem << endl;
}

``````
where a, b and n are defined as

Code: Select all

``````unsigned n;
unsigned a[25];
unsigned b[25];
``````
Good luck and have fun!

Burgi12345
New poster
Posts: 1
Joined: Tue Apr 05, 2011 2:51 pm

Submition says my answer is wrong. Im sure its not.

Maybe input or output is incorrect?

Code: Select all

``````	public static void main(String[] args) throws IOException
{

ArrayList<Integer> ratingOfStudents = new ArrayList<Integer>() ;

int counter = 0;
for (int i = 0; i < arr.length; i++)
{
if (!arr[i].equals(""))
{
counter ++;
}
}

//get the ratings of the students
{
}

//output
for (int i = 0; i < ratingOfStudents.size(); i++)
{
System.out.println(ratingOfStudents.get(i));
}
}``````

Thanks for help

jfvs
New poster
Posts: 12
Joined: Wed Feb 02, 2011 10:40 am