int main() { char a[100] = {0}, i, j = 0, n, s = 0, is_1st_digit = 1; int k; printf("Please input number a: "); scanf("%s", a); n = strlen(a); printf("Please tell me how many digits to be deleted: "); scanf("%d", &k); while (k > 0 && k < n - s) { for (i = s; i <= s + k; i++) { if (a[i] < a[j]) { if (!is_1st_digit || a[i] != '0') { j = i; } } } for (i = s; i < j; i++) { a[i] = -1; } k -= j - s; j++; s = j;
is_1st_digit = 0; } if (k > 0) { n = s; } // printf() the answer. for (i = 0; i < n; i++) { if (a[i] != -1) { printf("%c", a[i]); } } printf("\n"); return 0;
}