관리 메뉴

fatalite

Mars Exploration 본문

코딩 인터뷰/C++

Mars Exploration

fataliteforu 2023. 1. 18. 09:51

Letters in some of the SOS messages are altered by cosmic radiation during transmission.

Given the signal received by Earth as a string, s, determine how many letters of the SOS message have been changed by radiation.

Example

 

The original message was SOSSOS. Two of the message's characters were changed in transit.

Function Description

Complete the marsExploration function in the editor below.

marsExploration has the following parameter(s):

  • string s: the string as received on Earth

Returns

  • int: the number of letters changed during transmission

Input Format

There is one line of input: a single string s

int marsExploration(string s) {
    int changed = 0;
    for(int i = 0; i < s.size(); i = i + 3){
        if(s[i] != 'S'){
            changed++;
        }
        if(s[i+1] != 'O'){
            changed++;
        }
        if(s[i+2] != 'S'){
            changed++;
        }
    }
    return changed;
}

'코딩 인터뷰 > C++' 카테고리의 다른 글

Subarray Division 2  (0) 2023.02.03
Permuting Two Arrays  (0) 2023.01.26
Counting Valleys  (0) 2023.01.17
Diagonal Difference  (0) 2023.01.13
Flipping Bits  (0) 2023.01.12