Medium
Given some integer, find the maximal number you can obtain by deleting exactly one digit of the given number.
Example
- For n = 152, the output should be
deleteDigit(n) = 52; - For n = 1001, the output should be
deleteDigit(n) = 101.
Input/Output
-
[execution time limit] 0.5 seconds (c)
-
[input] integer n
Guaranteed constraints:
10 ≤ n ≤ 10^6. -
[output] integer
[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
int deleteDigit(int n)
{
int max=0;
char *str=(char *)calloc(8,sizeof(char));
sprintf(str,"%d",n);
for(int i=0;i<strlen(str);i++)
{
int N=0;
for(int j=0;j<strlen(str);j++)
{
if(i==j)
continue;
N*=10;
N+=str[j]-'0';
}
max=N>max?N:max;
}
free(str);
return max;
}
728x90
'Codesignal' 카테고리의 다른 글
<Codesignal> Valid Time (0) | 2020.04.06 |
---|---|
<Codesignal> longestWord (0) | 2020.04.06 |
<Codesignal> chessKnight (0) | 2020.04.06 |
<Codesignal> lineEncoding (0) | 2020.04.06 |
<Codesignal> isDigit (0) | 2020.04.06 |