Advertisement
palmerstone

Untitled

May 29th, 2011
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7. int wtf, fk, p, resultlen, l1, l2, t, i, j, k, l, m, n, x, y, z, a, b, c, d, count, flag, flag1, len1, len2, flag2;
  8. char dum, dum2, ch, str[10000], str2[10000], min[10000], max[10000], minreal[10000], result[10000];
  9.  
  10. scanf("%d", &t);
  11. scanf("%c", &dum);
  12. for (i = 1; i <= t; i++)
  13. {
  14. scanf("%s", str);
  15. scanf("%c", &dum);
  16. scanf("%s", str2);
  17. scanf("%c", &dum2);
  18. len1 = strlen(str);
  19. len2 = strlen(str2);
  20. flag2 = 0, wtf = 0;
  21.  
  22. if (len1 < len2)
  23. {
  24. strcpy(min, str);
  25. strcpy(max, str2);
  26. min[len1] = '\0';
  27. max[len2] = '\0';
  28. wtf = 2;
  29. }
  30. else if (len1 > len2)
  31. {
  32. strcpy(min, str2);
  33. strcpy(max, str);
  34. min[len2] = '\0';
  35. max[len1] = '\0';
  36. wtf = 1;
  37. }
  38. else if (len1 == len2)
  39. {
  40. z = strcmp(str, str2);
  41. if (z < 0)
  42. {
  43. strcpy(min, str);
  44. strcpy(max, str2);
  45. min[len1] = '\0';
  46. max[len2] = '\0';
  47. wtf = 2;
  48. }
  49. else if (z > 0)
  50. {
  51. strcpy(min, str2);
  52. strcpy(max, str);
  53. min[len2] = '\0';
  54. max[len1] = '\0';
  55. wtf = 1;
  56. }
  57. else
  58. {
  59. flag2 = 5;
  60. }
  61. }
  62.  
  63. if (flag2 == 5)
  64. {
  65. printf("0\n");
  66. }
  67. else
  68. {
  69. l1 = strlen(min);
  70. l2 = strlen(max);
  71.  
  72. l = l2 - l1;
  73. k = 0;
  74. for (j = 0; j < l; j++, k++)
  75. {
  76. minreal[k] = '0';
  77. }
  78. p = 0;
  79. for (k = j; k < l2; k++, p++)
  80. {
  81. minreal[k] = min[p];
  82. }
  83. minreal[l2] = '\0';
  84.  
  85. k = 0;
  86. p = 0;
  87. for (j = l2 - 1; j >= 0; j--)
  88. {
  89. x = max[j] - 48;
  90. y = minreal[j] - 48;
  91. if (k == 1)
  92. {
  93. y = y + k;
  94. }
  95. if (x < y)
  96. {
  97. //y = y + k;
  98. x = x + 10;
  99. k = 1;
  100. }
  101. else
  102. {
  103. k = 0;
  104. }
  105. z = x - y;
  106. result[p] = z + 48;
  107. p++;
  108. }
  109. result[p] = '\0';
  110. resultlen = strlen(result);
  111.  
  112. //printf("%s\n", max);
  113. //printf("%s\n", minreal);
  114. //printf("_________________\n");
  115. fk = 0;
  116. if (wtf == 2)
  117. {
  118. printf("-");
  119. }
  120. for (j = resultlen - 1; j >= 0; j--)
  121. {
  122. if (result[j] > 48)
  123. {
  124. fk = 5;
  125. }
  126. if (fk == 5)
  127. {
  128. printf("%c", result[j]);
  129. }
  130. }
  131. printf("\n");
  132. }
  133. }
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement