카타 8급 Correct the mistakes of the character recognition software

1 C[ | ]

char *correct(char *string) {
  char *p = string;
  while(*p) {
    switch(*p) {
      case '5': *p='S'; break;
      case '0': *p='O'; break;
      case '1': *p='I'; break;
    }
    p++;
  }
  return string;
}

2 C++[ | ]

#include <string>
std::string correct(std::string str){
  replace(str.begin(), str.end(), '5', 'S');
  replace(str.begin(), str.end(), '0', 'O');
  replace(str.begin(), str.end(), '1', 'I');
  return str;
}
#include <string>
std::string correct(std::string str){
  for(int i=0; i<str.length(); i++) {
    if(str[i] == '5') str[i] = 'S';
    else if(str[i] == '0') str[i] = 'O';
    else if(str[i] == '1') str[i] = 'I';
  }
  return str;
}
#include <string>
std::string correct(std::string str){
  for(auto &x: str){
    if(x == '1') x = 'I';
    else if(x == '0') x = 'O';
    else if(x == '5') x = 'S';
  }
  return str;
}

3 PHP[ | ]

function correct($string) {
  return str_replace(['5','0','1'], ['S','O','I'], $string);
}
function correct(string $string): string {
  return strtr($string, "501", "SOI");
}
function correct($string) {
  $string = str_replace('5','S',$string);
  $string = str_replace('0','O',$string);
  $string = str_replace('1','I',$string);
  return $string;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}