Diferență între revizuiri ale paginii „DSA Homework 2”
Linia 13: | Linia 13: | ||
== Output Data == | == Output Data == | ||
− | A file called anagrams.out containing the number K of auxiliary words that are anagrams of the initial word and on the next K lines, the auxiliary words themselves, in the order they appear in the input file. | + | A file called ''anagrams.out'' containing the number K of auxiliary words that are anagrams of the initial word and on the next K lines, the auxiliary words themselves, in the order they appear in the input file. |
== Restrictions == | == Restrictions == |
Versiunea curentă din 13 martie 2014 21:17
Anagrams
Little John is training for a Scrabble competition and he writing a program to help. He writes a text file in which, on the first line, he puts a sequence of letters and on subsequent lines a series of words. In the output file, he wants to have the list of words that are anagrams of the letter sequence on the first line.
Requirement
Given an initial word and a set of auxiliary words, identify all words that are anagrams of the initial one.
Input Data
A file called anagrams.in, containing the initial word on the first line, the number N of auxiliary words on the second line, and N lines with one auxiliary word per line.
Output Data
A file called anagrams.out containing the number K of auxiliary words that are anagrams of the initial word and on the next K lines, the auxiliary words themselves, in the order they appear in the input file.
Restrictions
1 ≤ N ≤ 10000
Examples
Input | Output |
abcdef
5
abdc
jfhry
dcbafe
cadafe
cbaefd
|
2
dcbafe
cbaefd
|
Explanation: dcbafe and cbaefd are the only ones that are anagrams of abcdef.