Will the readline() function only work once? I’m going through a for loop and after all five lines of the text are read, ROW becomes null.
Hi all guys) I am using C++ and I am on ASCII Art task. I got stucked on MANHATTAN test
Everything is fine and ok, but when I start my tests - I pass 4/5 of the tests, because of the same name to variable T in 2 tests - simple MANHATTAN & MANHATTAN with another ASCII representation…I don’t know what to do and how to complete it on 100%, because these two tests use the same string…so how to make them work simultaneously and to gain 100%? Share experience please) Thx in advance
It sounds like you hardcoded part of your solutions… Your solution should be able to record the given ASCII representation and transform arbitrary strings with that representation.
I’m attempting to solve this puzzle in Bash after having solved it in a multitude of different languages. However, when reading the rows for the font, I get inconsistent lengths of strings. Does anyone have any clues on how to fix this problem?
Hello!
You may consider that “read” gives you binary data. It does not. “help read” to know more about this command.
The advice is to use the ability to define a variable for only one command and to change the separator, preventing space to bother you. Moreover, use the “-r” option to prevent anti-slashes being interpreted.
Here is one line giving input in my final solution that received 100%
IFS='' read -r ROW
I easily understand this problem occurs only in bash.
Good luck.
Thanks for the pointers, I got it to work
I’m trying to solve this in JavaScript, all the test cases pass, but the validation is giving me fits. I pass everything except:
Test Lorem ipsum dolor sit amet,…
Test full alphabet in CAPS WMADXESFGIJVTHKNOBPLYQRUZC
I’m assuming that the output they’re looking for in the first one is “LOREM?IPSUM?DOLOR?SIT?AMET???”
and the second one “FULL?ALPHABET?IN?CAPS?WMADXESFGIJVTHKNOBPLYQRUZC”.
I don’t see how my code wouldn’t produce those results.
My basic methodology:
Storing the ASCII alphabet:
- Push substrings of length L from ROW into a temporary array until I
get to the end. - Push that array (which has the entire row split into its component letter pieces) into another array, alpha.
- The end result is a two-dimensional array, alpha[H][26] containing strings of length L
Putting together the ASCII string:
For every character in the input phrase, concatenate its ASCII art string from alpha for the current row onto a temporary string, and then push that temporary string (which should contain a complete row of the phrase’s ASCII art) onto an answer[] array. Once all the rows have been put into the answer, print each element of answer[] in turn.
This was good enough to pass the test cases and most of the validation, except for those two cases. The only thing that you might maybe consider “hard-coding” is the code I use to figure out which part of the alpha[] array to access to put together the answer. It takes each character of the input phrase and uses a switch statement to decide which part to access (case ‘A’: case ‘a’: case’B’: case ‘b’: etc, etc.). It checks for all the [a-z] and [A-Z] characters, with the default case accessing the “?” part of alpha[].
As I said, I would think that would produce the uppercase ASCII art for any letters, and the question mark ASCII art for everything else, including spaces and punctuation. Can anyone tell me what I’m doing wrong?
The other validation cases have punctuation marks, and they pass, so it must be hanging up on the spaces or something.
You have a switch statement with 54 cases? That’s a lot of room for errors.
If you want to get the number of a letter you can do "ABCDEFGHIJKLMNOPQRSTUVWXYZ?".indexOf("x".toUpperCase())
. If that is -1
you have to use the index of ?
.
It worked well enough to pass all the test cases. Originally I used toUpperCase in the switch statement to catch lowercase letters, but that failed the validation too, so I decided to try cases for the lowercase letters as well, just using fall-through, like
case ‘A’:
case ‘a’:
//do something
break;
That also passed all the test cases, but failed the validation tests. The only difference between the ones that pass and the ones that fail is that the failures have spaces. It must have something to do with that. I’m not really looking for a “better” way of doing it, just the reason why the way I’m doing it isn’t working.
My guess is you wrote one case, copied it like 26 times and then changed little bits here and there to make it work (with the testcases). A mistake happened (that doesn’t affect the testcases) and now you don’t see it, because it all looks the same. That’s why I suggested to replace the switch statement.
There is hardly any room for errors in that one line. If that line works for one letter it will work for all the other letters too.
That’s different to your big switch statement. Especially if //do something
is a bit more involved than simply returning a number. If the case for one letter works it says nothing about the other cases.
Hey @ all,
I am using C# and for the moment I’m really at a loss what to do. I don’t have any idea. Maybe somenone coult help me with a short “push” in the right direction.
All I know : the ASCII signs coming in in 5 rows by the Var ROW, every sign is 4 Char width. T covr the string which has to be changed into ASCII.
My first thoughts were to save everything in an array and get it sign by sign. But this way is horrable and really complicated. I’m sure that there must be an easier way.
I just need a short “ignition”, please.
Thanks !!
Hoschie
The ASCII tables are changing from a test to another. Don’t count on hardcoding.
The ascii alphabet is always in the same order, you just have to find the index of the letter you want (A:0,[…],Z:25, other:26).
Then you can use ROW.Substring() with some arguments, to get the ascii part of your current letter
IGNITION!!
Thanks a lot!
If I could get a hand, that’d be great. I’ve got this one working beautifully for all the test cases, but for some reason, it keeps telling me that it Expected “#” Found “” even though that I can see right above that in the output window that the answer was outputted exactly as wanted. Is there some common mistake I might be making here? Here’s an example:
It’s hard to see because of the way Pastebin displays, but it’s MANHATTAN
Figured it out, I was outputting null null null null as the first line of every character
HEY! Everyone who’s having issue with the Lorem Ipsum test! Remember, Lorem Ipsum contains more than one word.
That means that some input streams will only read the first word.
For example, I was having issues because I was using
cin >> target;
To read the target word, and that worked fine for all the tests that only had one word, but as soon as lorem ipsum was hit, it ignored everything after the first word, and printed out the answer as just “Lorem”
Make sure you use a read in that can get the entire line, and not just the first word.
I can’t get pass the second puzzle , could someone give me a hint on how to pass?
Edit:No Full Code
first: what language is this? is this go or javascript?