Rectangle logo from words

To read the 4 words into a vector of string:

#include <vector>
#include <string>
#include <iostream>

int main() {
	std::vector<std::string> words(4);

	for (auto& w : words)
		std::cin >> w;

Then you need to determine the order if possible.

For possible, 2 pairs need to have the same length and the first/last letter of the appropriate pair need to match. Once you know the ordering, then it can be displayed.
For any set of 4 words there are only 24 ways of distributing them amongst the four sides. It doesn't take long to check the validity of 24 things.
I swear I already responded to this exact question. Was it on SO?

This is a super duper simple assignment.

  ① Check to see that the ends of the words match such that the logo is possible
  ② Draw the logo

Here it is:

Answer is the same. You’ve got to attempt to write the code yourself.
I personally find this kind of thing fun, and would be happy to write my own version. But you learn absolutely nothing from my doing your (super easy) homework for you.

I think your a lazy suck-up who can’t be bothered to spend the bare minimum effort to learn the absolute basic requirements of programming, and you think your moronic comment is a slick come-back.

People in every profession the world over are stuck working with jack-arses like yourself who think everyone else is responsible for their own lack of effort.

In CS, son, it is not uncommon to be told to read and learn stuff that would print to an inch-thick technical manual overnight. We’re four months into the semester and you can’t write a star-triangle program.

How’s that for a life lesson? You’re now on my loser list. Good luck with that.
I think you just don't know how to do it yourself.

For the moment, forget code. Given the problem as a pen/paper exercise, how would you go about doing it? Once you know that, what instructions would you give to someone else to do it who didn't know the requirement? Once you have those, then you can develop a program design and then finally you code the program from the design.

But the initial first step is to devise the algorithm to use. This is the important part of the task. If you don't know how to solve, you can't code it. You can only code a solution once you know how it's done.

This isn't really a coding problem. It's an algorithm problem where the solution design could just as easily be coded in another language. But developing the algorithm/steps to produce the required output requires logical thought re the problem.

Once you have the design/algorithm and you then have difficulty coding from that, then ask a coding question for further guidance.

design then code

code as design
Last edited on
There are a bunch of quick tests you can do to fail without doing much real work, if you want (eg 4 words should have 2 or 1 different lengths. that is, either all 4 are same length, or 2 sets of 2 words are the same length. Matching pairs of the start/end letters is also a valid test, dump them all to a string and sort it.

That isnt necessary, just a faster way to not do extra work.
pure brute force works. peel letters off the words (start and end letters only) and arrange them such that it works. If you find a working combo, test that it is valid and if so, you are done.

that gives jl js ld sd
because the words are oriented left/right up/down only (presumably?) the upper left has to be starting letters only. the only possibility is j. (brute force code tests all the combos ... it can't 'see' that)
same reason, the lower right has to be end letters only. the only possibility is d.
now your grid looks like
and you keep going, and of course it works.
Last edited on
Your problem isn't well-defined (as far as the bottom and right words are concerned).

For example, given the words THREE, TERSE, EXALT, EVENT
is the solution
X   H
A   R
L   E

X   E
A   R
L   S

(or doesn't it matter).

Anyway, one way of doing it is to check 24 potential solutions for validity (use permutations of the indices 0,1,2,3 to reorder your strings) and check
- top and bottom have same length;
- left and right have same length;
- top length >= left length (avoiding any "non-preferred" solution);
- the four corners match in respective words;

Then you just have to decide which of any valid arrangements is the "preferred" one (after you tightened the definition of the problem as above).
Last edited on
I think you just don't know how to do it yourself.

Problems of this difficulty are regularly in "Clash of Code" on - where you're expected to solve it within 15 minutes. You only win by either coding it the fastest or with the least amount of code.

In fact, it wouldn't be at all unreasonable for a problem this easy to be given without any description at all - just the input and the output and you have to figure out what is happening and code it within 15 minutes.

To say someone here couldn't do it themselves would be a similar insult to someone telling you that you don't know how to take out the trash.

Now, the problem itself:

You want to check which word meets these conditions:

1. The first letter matches the first letter of another word
2. The last letter matches the first letter of another word
3. The two previous words match length
4. The last remaining word begins with ending letter to #1 and ends with the ending letter of #2

The word that fits this criteria will be the top word, the word printed on top. Since your only criteria is to prefer the longest words at the top, you begin checking the longest words first.

I'm procrastinating other things and actually coded a solution, took about 20 minutes of casual coding.
Hmmmmm, someone gave the "gimme" muppet the boot. So sad.....

He was just as "give me the code for free" demanding over at SO as well.
Topic archived. No new replies allowed.