fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. int main(void) {
  6. char * number;
  7. int instances;
  8. scanf("%d", &instances);
  9. int i;
  10. for (i = 0; i < instances; i++){
  11. number = malloc(sizeof(char)*(10000000));
  12. scanf("%s", number);
  13. int len = strlen(number);
  14. int k;
  15. int flag = 1;
  16.  
  17. // In case the number is all 9s
  18. for (k = 0; k < len; k++){
  19. if (number[k] != '9'){
  20. flag = 0;
  21. }
  22. }
  23.  
  24. if (flag == 1){
  25. printf("1");
  26. for (k = 0; k < len - 1; k++){
  27. printf("0");
  28. }
  29. printf("1\n");
  30.  
  31. }
  32. else{
  33. int left = (int)ceil((double)len / 2)-1;
  34. int right;
  35. if(len%2 == 0)
  36. right = left+1;
  37. else
  38. right = left;
  39.  
  40. for (k = 0; k <= (int)floor(len / 2.0); k++){
  41. // if middle numbers are not nines
  42. if ((number[left] != '9') && (number[right] != '9')){
  43. int numL = number[left];
  44. int numR = number[right];
  45. number[left--] = (char)(numL + 1);
  46. number[right++] = (char)(numR + 1);
  47. break;
  48. }
  49. else{
  50. number[left--] = '0';
  51. number[right++] = '0';
  52. }
  53. }
  54. printf("%s\n", number);
  55. }
  56. }
  57. free(number);
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 109440KB
stdin
12
1
9
12
99
101
999
1001
808
900000000000000000000000000000000000009
123454321
1999999999991
199999999991
stdout
2
11
23
101
111
1001
1111
818
900000000000000000010000000000000000009
123464321
2000000000002
200000000002