Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Edit: In response to your comment I have now gone back to using strings as patterns:</p> <pre><code>#define UNKNOWN_LETTER_PATTERN "" string texttopattern(char c) { string code[] = {"1","12","14","145", "15", "124", "1245", "125", "24", "245", "13", "123", "134", "1345", "135", "1234", "12345", "1235", "234", "2345", "136", "1236", "1346", "13456", "1356", "12346"}; if (c &gt;= 'a' &amp;&amp; c &lt;= 'z') return code[c - 'a']; else return UNKNOWN_LETTER_PATTERN ; } </code></pre> <p>First part of <code>main()</code> stays the same:</p> <pre><code>int main() { string ord; getline(cin, ord); vector&lt;string&gt; code; for(int i=0; i&lt;ord.length(); i++) { code.push_back(texttopattern(ord[i])); } </code></pre> <p>Updated the rest and added a few comments, hopefully explaining what I am doing:</p> <pre><code> // Loop patterns for (vector&lt;string&gt;::iterator it = code.begin(); it != code.end(); it++) { if (*it == UNKNOWN_LETTER_PATTERN ) { // Don't know what to do with unknown chars like spaces - your problem cout &lt;&lt; "unknown letter" &lt;&lt; endl; } else { // Loop every digit in the current pattern for (int i = 0; i &lt; it-&gt;size(); i++) { char c = it-&gt;at(i); // There surely is a better way to do the following, atoi or // stringstream come to mind // But for a single digit number, this should be enough for // now to convert a char to a number. int number = c - '0'; // loop until number is reached for (int j = 0; j &lt; number; j++) cout &lt;&lt; "I"; cout &lt;&lt; endl; } cout &lt;&lt; "End of letter" &lt;&lt; endl; } } cin.get(); return 0; } </code></pre> <p>EDIT: I changed the above sample. What it now does is, for example: input is 'd' -> resolve to code "145" -> loop every digit and turn to number [1, 4, 5] -> print 'I' <em>number</em> times for each digit "I IIII IIIII". After rereading your comment, I believe this is what you wanted.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload