I have a fairly involved question about how to start writing a c++ program, I know how to use different things in c++ but I don't know how to put it all together. here is the question. Where should I start the programming for this?
For this problem, you are given an abbreviated “dictionary” (see below). Your program should read a string of digits (from 2 to 9, not using 1 as space) from the console and find the words in the dictionary whose spellings contain that series of consecutive digits anywhere within the word. If there are no matches, print the string 'No matches'. If there is one match, print the matching word. If there are n > 1 matches, print the string 'n matches:' followed by the matching words, one per line. Here is the dictionary to be used for this problem with the numeric spellings of each word:
ah so they type in 246 and get chocolate and cinnimon and cappuchino etc?
and I assume this is a challenge / timed problem too, right?
you need a way to rapidly eliminate data to avoid searching things that are no use.
eg for the 246 example, how do you avoid looking thru latte for what cannot be there?
or, if you can find one, a way to directly get a yes/no from a word without searching its pattern.
the point is to find either no matches, 1 matches, 2 matches, etc.
yes, that is what I am looking to do, find a way to search the dictionary for anything that matches and print out all the matches but I don't know how to define them so it will be easy to code what I will need.
I have never learned about std::map, if that would work in this case.
If I understand your problem, I think a vector of a struct with two strings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// read the pairs into v
// for each input
// loop through v checking if the input string is a substring
// of the NameCode's code.
> I know how to use different things in c++ but I don't know how to put it all together.
> I am have not heard of struct before
You need to pick up the pace on learning new things.
You don't need to memorise the manual pages, but knowing in high level terms what the features are and what they're typically used for helps you get started on new problems. Like for example knowing what all the containers are. https://en.cppreference.com/w/cpp/container
> I have never learned about std::map, if that would work in this case.
Then allow me to demonstrate.
well, what I was trying to say was, for substring searching you want to minimize the # of calls to find() if you can, by storing the data in a way that you can ignore parts of your dictionary, because you know the substring can't be in there. If you are doing one of those challenges with a huge dictionary and a time limit, we can explore that.