code.cpp 619 B

123456789101112131415161718
  1. /* Create a function that takes a string as an argument
  2. ~ and returns a coded (h4ck3r 5p34k) version of the string.
  3. ~ In order to work properly, the function should replace
  4. ~ all 'a's with 4, 'e's with 3, 'i's with 1, 'o's with 0, and 's's with 5.
  5. */
  6. std::string hackerSpeak(std::string str) {
  7. std::string empty = "";
  8. for (int i=0;i<str.size();i++){
  9. switch(str[i]) {
  10. case 'a' : str.replace(i,1,"4"); break;
  11. case 'e' : str.replace(i,1,"3"); break;
  12. case 'i' : str.replace(i,1,"1"); break;
  13. case 'o' : str.replace(i,1,"0"); break;
  14. case 's' : str.replace(i,1,"5"); break;
  15. }
  16. }
  17. return str;
  18. }