title: Replace Character C1 C2 C2 C1 String S
signature: replace_character_c1_c2_c2_c1_string_s <- function(s, c1, c2) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(s, c1, c2, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(s, c1, c2), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          "IZTSMw j", 'W', 'k', 
          "IZTSMw j"
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          "7288334", '6', '9', 
          "7288334"
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          "010110000", '1', '1', 
          "010110000"
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          "b gJX", 't', 'P', 
          "b gJX"
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          "734", '4', '4', 
          "734"
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          "1", '1', '1', 
          "1"
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          "xCaUKdhA", 'X', 'S', 
          "xCaUKdhA"
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          "4370992644981", '5', '6', 
          "4370992544981"
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          "01010", '0', '1', 
          "10101"
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          "ZNIFGshaWA", 'Q', 'x', 
          "ZNIFGshaWA"
      )))
  
  }
  
  main()
source_py: def replace_character_c1_c2_c2_c1_string_s(s, c1, c2):
      l = len(s)
      for i in range(l):
          if (s[i] == c1):
              s = ((s[0:i] + c2) + s[(i + 1):])
          elif (s[i] == c2):
              s = ((s[0:i] + c1) + s[(i + 1):])
      return s
source_cpp: string replace_character_c1_c2_c2_c1_string_s(string s, char c1, char c2) {
    int l = s . length ( );
    for ( int i = 0;
    i < l;
    i ++ ) {
      if ( s [ i ] == c1 ) s [ i ] = c2;
      else if ( s [ i ] == c2 ) s [ i ] = c1;
    }
    return s;
  }