Easy
Consider the following ciphering algorithm:
- For each character replace it with its code.
- Concatenate all of the obtained numbers.
Given a ciphered string, return the initial one if it is known that it consists only of lowercase letters.
Note: here the character's code means its decimal ASCII code, the numerical representation of a character used by most modern programming languages.
Example
For cipher = "10197115121", the output should be
decipher(cipher) = "easy".
Explanation: charCode('e') = 101, charCode('a') = 97, charCode('s') = 115 and charCode('y') = 121.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] string cipher
A non-empty string which is guaranteed to be a cipher for some other string of lowercase letters.
Guaranteed constraints:
2 ≤ cipher.length ≤ 100. -
[output] string
[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 *decipher(char *cipher)
{
char *string=calloc(51,sizeof(char));
int temp=0, count=0;
for(int i=0;i<strlen(cipher);i++)
{
temp*=10;
temp+=cipher[i]-'0';
if(temp>='a' && temp<='z')
{
string[count++]=temp;
temp=0;
}
}
return string;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> Construct Square (0) | 2020.12.30 |
---|---|
<Codesignal> Crossword Formation (0) | 2020.12.30 |
<Codesignal> Higher Version (0) | 2020.06.27 |
<Codesignal> Is Unstable Pair? (0) | 2020.06.26 |
<Codesignal> Equal Pair of Bits (0) | 2020.06.17 |