Easy

When you recently visited your little nephew, he told you a sad story: there's a bully at school who steals his lunch every day, and locks it away in his locker. He also leaves a note with a strange, coded message. Your nephew gave you one of the notes in hope that you can decipher it for him. And you did: it looks like all the digits in it are replaced with letters and vice versa. Digit 0 is replaced with 'a', 1 is replaced with 'b' and so on, with digit 9 replaced by 'j'.

The note is different every day, so you decide to write a function that will decipher it for your nephew on an ongoing basis.

Example

For note = "you'll n4v4r 6u4ss 8t: cdja", the output should be
stolenLunch(note) = "you'll never guess it: 2390".

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] string note

    A string consisting of lowercase English letters, digits, punctuation marks and whitespace characters (' ').

    Guaranteed constraints:
    0 ≤ note.length ≤ 500.

  • [output] string

    • The deciphered note.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

char *stolenLunch(char *note)
{
	for(int i=0;i<strlen(note);i++)
		if(isdigit(note[i]))
			note[i]+=49;
		else if(isalpha(note[i])&&note[i]<107)
			note[i]-=49;

	return note;
}

 

728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Different Rightmost Bit  (0) 2020.06.16
<Codesignal> Swap Adjacent Bits  (0) 2020.06.16
<Codesignal> Cipher 26  (0) 2020.05.29
<Codesignal> New Numeral System  (0) 2020.05.24
<Codesignal> Reflect String  (0) 2020.05.24

+ Recent posts