+ 1

Secret message code coach

Explanation in the code. Code at the bottom. https://code.sololearn.com/cB274uGP7I6F/?ref=app

28th Jan 2022, 3:43 AM
Nathaniel
Nathaniel - avatar
4 Answers
+ 1
/* line 1>>for (int i=0;alphabet[i]!='/0'; i++) { if line 2>>(phrase[j]==alphabet[i]&&phrase[j!=' ']) line 3>>{phrase[j]=alphabet[25-i]; line4 >> i=0; j++; //this part transform the char in the corresponding coded char, it reset i to make the loop go over the alphabet again, and it add one to j to get to the next char in "phrase". } } */ Make it like for (int i=0;alphabet[i]!=false; i++) { if (phrase[j]==alphabet[i]&&phrase[j]!=' '){phrase[j]=alphabet[25-i]; i=0; j++; // why u should change it to false on line 1 because space char not in your Alphabets string // line 2 changes make the loop skip run further when the space char in the phrase comes } } It's work
28th Jan 2022, 5:19 AM
Yesudasan Ebenezer
Yesudasan Ebenezer - avatar
+ 1
Oh wow it was a stupid error I didn't notice. But it still not working it only change 6 char in the first test case and 5 in the second. When I try some input myself it seems random sometime it change only the first char. Really weird.
28th Jan 2022, 7:03 AM
Nathaniel
Nathaniel - avatar
+ 1
Change the line 4 as i=-1 because when you change the value of i to 0 and the loop was end and i++ was executed so it run the loop form 1 to 25 not 0 to 25 then the loop was exit , error was born // And make a another if statement like if (phrase[i]==' '){ i=-1; j++; } it make further loop run
28th Jan 2022, 7:28 AM
Yesudasan Ebenezer
Yesudasan Ebenezer - avatar
+ 1
Hey thank you! I understand everything now!
28th Jan 2022, 7:35 AM
Nathaniel
Nathaniel - avatar