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. inbuff[fread(inbuff, 1, 2500000, stdin)] = '\0';
  19.  
  20. /* Skip whitespace before first number and check if end of input */
  21. do {
  22. c = *(in++);
  23. } while(c != '\0' && !(c >= '0' && c <= '9'));
  24.  
  25. /* If end of input, print answer and return */
  26. if(c == '\0') {
  27. *(--out) = '\0';
  28. puts(outbuff);
  29. return 0;
  30. }
  31.  
  32. /* Read first integer */
  33. do {
  34. i = 10 * i + (c - '0');
  35. c = *(in++);
  36. } while(c >= '0' && c <= '9');
  37.  
  38. /* Skip whitespace between first and second integer */
  39. do {
  40. c = *(in++);
  41. } while(!(c >= '0' && c <= '9'));
  42.  
  43. /* Read second integer */
  44. do {
  45. j = 10 * j + (c - '0');
  46. c = *(in++);
  47. } while(c >= '0' && c <= '9');
  48.  
  49. if(i > j)
  50. res = i-j;
  51. else
  52. res = j-i;
  53.  
  54. /* Buffer answer */
  55. unsigned long long divisor = 1000000000;
  56. /* Skip trailing 0s until the last one */
  57. while(res / divisor == 0 && divisor >= 10) {
  58. divisor /= 10;
  59. }
  60. /* Buffer digits */
  61. while(divisor != 0) {
  62. unsigned long long digit = res / divisor;
  63. *(out++) = digit + '0';
  64. res -= divisor * digit;
  65. divisor /= 10;
  66. }
  67. *(out++) = '\n';
  68. }
  69. }
Success #stdin #stdout 0s 15072KB
stdin
10 12
10 14
100 200
100 100
0 0
4294967296 0
4294967296 4294967296
stdout
2
4
100
0
0
4294967296
0