fork download
  1. /*
  2. You should use the standard input/output
  3.  
  4. in order to receive a score properly.
  5.  
  6. Do not use file input and output
  7.  
  8. Please be very careful.
  9. */
  10.  
  11. #include <iostream>
  12. #include <math.h>
  13.  
  14. using namespace std;
  15.  
  16. int Answer;
  17.  
  18. int main(int argc, char** argv)
  19. {
  20. int T, test_case, N, K, count, tempcount, tempscore, i, temps;
  21. int ability[1000];
  22. int temp[100];
  23. /*
  24. The freopen function below opens input.txt file in read only mode, and afterward,
  25. the program will read from input.txt file instead of standard(keyboard) input.
  26. To test your program, you may save input data in input.txt file,
  27. and use freopen function to read from the file when using cin function.
  28. You may remove the comment symbols(//) in the below statement and use it.
  29. Use #include<cstdio> or #include <stdio.h> to use the function in your program.
  30. But before submission, you must remove the freopen function or rewrite comment symbols(//).
  31. */
  32.  
  33. // freopen("input.txt", "r", stdin);
  34.  
  35. cin >> T;
  36. for(test_case = 0; test_case < T; test_case++)
  37. {
  38. tempcount = 0;
  39. tempscore = 0;
  40. Answer = 0;
  41. cin >> N;
  42. cin >> K;
  43. for(int range = 0; range < N; range++)
  44. {
  45. cin >> ability[range];
  46. }
  47.  
  48. if(N == 1)
  49. {
  50. Answer = 1;
  51. }
  52. else
  53. {
  54. for (int w = 0; w < N - 1; w++)
  55. {
  56. for (int j = 0; j < N - 1 - w; j++)
  57. {
  58. if (ability[j] > ability[j + 1])
  59. {
  60. temps = ability[j];
  61. ability[j] = ability[j + 1];
  62. ability[j + 1] = temps;
  63. }
  64. }
  65. }
  66. temp[tempcount++] == ability[0];
  67. for(int range = 1; range < N; range++)
  68. {
  69. for(i = 0; i < tempcount; i++){
  70. if(abs(ability[range] - temp[i]) == K || abs(ability[range] - temp[i]) < K)
  71. {
  72. tempscore = tempscore + 1;
  73.  
  74. }
  75. }
  76. if(tempscore == i+1)
  77. {
  78. tempcount++;
  79. }
  80. }
  81. Answer = tempcount;
  82. }
  83.  
  84. for(int range = 0; range < N; range++)
  85. {
  86. ability[range] = 0;
  87. }
  88.  
  89.  
  90. /////////////////////////////////////////////////////////////////////////////////////////////
  91. /*
  92. Implement your algorithm here.
  93. The answer to the case will be stored in variable Answer.
  94. */
  95.  
  96.  
  97.  
  98. /////////////////////////////////////////////////////////////////////////////////////////////
  99.  
  100. // Print the answer to standard output(screen).
  101. cout << "Case #" << test_case+1 << endl;
  102. cout << Answer << endl;
  103. }
  104.  
  105. return 0;//Your program should return 0 on normal termination.
  106. }
Success #stdin #stdout 0s 4568KB
stdin
3
1 1
2
2 3
1 4
5 3
1 5 3 7 9
stdout
Case #1
1
Case #2
1
Case #3
1