fork(1) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. int main()
  5. {
  6. unsigned long long int i, j, res;
  7.  
  8. unsigned char inbuff[2500000]; /* To be certain there's no overflow here */
  9. unsigned char *in = inbuff;
  10. char outbuff[2500000]; /* To be certain there's no overflow here */
  11. char *out = outbuff;
  12.  
  13. int c = 0;
  14.  
  15. while(1) {
  16. i = j = 0;
  17.  
  18. fseek(stdin, 0, SEEK_END);
  19. long inputsize = ftell(stdin);
  20. rewind(stdin);
  21. fread(inbuff, inputsize, 1, stdin);
  22. inbuff[inputsize] = '\0';
  23.  
  24. /* Skip whitespace before first number and check if end of input */
  25. do {
  26. c = *(in++);
  27. } while(c != '\0' && !(c >= '0' && c <= '9'));
  28.  
  29. /* If end of input, print answer and return */
  30. if(c == '\0') {
  31. *(--out) = '\0';
  32. puts(outbuff);
  33. return 0;
  34. }
  35.  
  36. /* Read first integer */
  37. do {
  38. i = 10 * i + (c - '0');
  39. c = *(in++);
  40. } while(c >= '0' && c <= '9');
  41.  
  42. /* Skip whitespace between first and second integer */
  43. do {
  44. c = *(in++);
  45. } while(!(c >= '0' && c <= '9'));
  46.  
  47. /* Read second integer */
  48. do {
  49. j = 10 * j + (c - '0');
  50. c = *(in++);
  51. } while(c >= '0' && c <= '9');
  52.  
  53. if(i > j)
  54. res = i-j;
  55. else
  56. res = j-i;
  57.  
  58. /* Buffer answer */
  59. unsigned long long divisor = 1000000000;
  60. /* Skip trailing 0s until the last one */
  61. while(res / divisor == 0 && divisor >= 10) {
  62. divisor /= 10;
  63. }
  64. /* Buffer digits */
  65. while(divisor != 0) {
  66. unsigned long long digit = res / divisor;
  67. *(out++) = digit + '0';
  68. res -= divisor * digit;
  69. divisor /= 10;
  70. }
  71. *(out++) = '\n';
  72. }
  73. }
Success #stdin #stdout 0s 14176KB
stdin
10 12
10 14
100 200
100 100
0 0
4294967296 0
4294967296 4294967296
stdout
2
4
100
0
0
4294967296
0