1997 Canadian Computing Competition, Stage 1

Problem A: Sentences

Write a program which accepts as input a list of subjects, a list of verbs, and a list of objects, and produces all possible sentences which consist of a subject, a verb, and an object.

Input

The first line of the input file contains a positive integer n which is the number of data sets which follow. For each of the n data sets, the data begins with three positive integers, one per line, each less than or equal to 20, which represent the number of subjects, verbs, and objects, respectively, which are provided. Following this line are the subjects, one per line in alphabetical order, the verbs, one per line in alphabetical order, and the objects, one per line in alphabetical order. The maximum length of any subject, predicate or object is 25 characters.

Output

The output is to consist of all possible sentences which can be formed using one subject, one verb, and one object, and is to be output in alphabetical order with a period at the end of each sentence. The output for different data sets are to be separated by a single blank line.

Sample Input

1
3
3
2
He
The cat
The dog
bit
kicked
saw
him
the mouse

Sample Output

He bit him.
He bit the mouse.
He kicked him.
He kicked the mouse.
He saw him.
He saw the mouse.
The cat bit him.
The cat bit the mouse.
The cat kicked him.
The cat kicked the mouse.
The cat saw him.
The cat saw the mouse.
The dog bit him.
The dog bit the mouse.
The dog kicked him.
The dog kicked the mouse.
The dog saw him.
The dog saw the mouse.

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 28, 2008

Problem Types: [Show]

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

I am getting 0/10, have tested my code with the Sample Input, have run test cases of my own, and sat here scratching my head while trying to debug my code. If anyone could help me, it would be greatly appreciated. Thank you.

Did you try a case with
n != 1
?

I am getting 0/10. Please help.

Please read the PEG Members section.
https://wcipeg.com/announcement/3719

Your program only works for one data set at a time. Please re-read the problem description.

you might want to use some arrays for this.
since input size is small, nested loops will run in time
here is some psuedo code:
 
#include<bits/stdc++.h>
#include<fstream>
#include<iostream>
int main(){
cin>>x
for{
cin>>subjects;
cin>>verbs;
cin>>objects;
arr1[]//subjects
arr2[]//verbs
arr3[]//objects
for{
cin>>arr1[] = subjects
}
for{
cin>>arr2[] = verbs
}
for{
cin>>arr3[] = objects
}
for{
for{
for{
cout<<(arr1[]+" "+arr2[]+" "+arr3[])<<endl;
}
}
}
}

My submissions are getting a consistent 0/10, even though I've tested my code.

After looking over my code, I can't find anything. Am I missing something small, like no space after a period, or something like this?

I feel like I should be getting something like a 1 to 9 /10, if there was a problem with the algorithm.

Thanks.

In this question, you can only possibly get 0/10 or 10/10.

Also, it doesn't appear to me that you've run your code on the sample input.

I don't know why my submission is false...

Read this post.

Alphabetical order is not the same as ASCIIbetical order. Note that the input is already given in alphabetic order.

the dog bit him.

he bit the dog