fork(79) download
  1. /******************************************************************************
  2.  
  3.   Online C++ Compiler.
  4.   Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <cmath>
  11. #include <sstream>
  12. #include <fstream>
  13. #include <typeinfo>
  14. using namespace std;
  15. int T ;
  16. int F,L;
  17. int thisNumber ;
  18. int count ;
  19. // Function to find that number divisble by 9 or not
  20. int check(string str)
  21. {
  22. // Compute sum of digits
  23. int n = str.length();
  24. int digitSum = 0;
  25. for (int i=0; i<n; i++)
  26. digitSum += (str[i]-'0');
  27.  
  28. // Check if sum of digits is divisible by 9.
  29. return (digitSum % 9 == 0);
  30. }
  31.  
  32. bool is_integer(float k)
  33. {
  34. return std::floor(k) == k;
  35. }
  36.  
  37. bool nine_test(int thisNumber)
  38. {int thisDigit;
  39. while (thisNumber != 0)
  40. {
  41. thisDigit = thisNumber % 10; // Always equal to the last digit of thisNumber
  42. thisNumber = thisNumber / 10; // Always equal to thisNumber with the last digit
  43. // chopped off, or 0 if thisNumber is less than 10
  44. if (thisDigit == 9)
  45. {
  46. return(true);
  47. }
  48. }
  49. return(false);
  50. }
  51. bool test(int k)
  52. {
  53. stringstream ss;
  54. ss << k;
  55. string str = ss.str();
  56. if ( (!is_integer(k)) || (check(str)) || (nine_test(k)))
  57. {
  58. return (false);
  59. }
  60. return(true);
  61. }
  62. int main()
  63. {
  64. ifstream infile ("A_small_practice.txt");
  65. ofstream myfile;
  66. myfile.open("myfile.txt");
  67. //infile.open("A-small-practice.txt");
  68. infile >> T;
  69. //std::cout <<"this is the T : "<< T <<" and this is the type : "<< typeid(T).name()<<std::endl;
  70.  
  71. for (int i=1; i<=T; ++i)
  72. {
  73. while(infile >> F >> L)
  74. count = 0 ;
  75.  
  76. for (int j=F ; j<=L; ++j)
  77. {
  78.  
  79. if (test(j))
  80. {
  81. count++;
  82. }
  83. }
  84. cout << "Case #" << i << ": " << count << endl;
  85. myfile << "Case #" << i << ": " << count << endl;
  86. }
  87. infile.close();
  88. myfile.close();
  89. return 0;
  90. }
  91.  
Success #stdin #stdout 0s 4396KB
stdin
100
88 102
372 461581
427480 427487
747466 846825
840 111021
325 257248
453 705313
218065 218074
512 880446
350 657250
248 480874
667832 884126
453 821647
102831 303586
777630 814525
7 526182
678383 678388
211166 410071
810178 810188
437 643143
220133 220141
7044 205276
263 606124
118 630123
21736 21746
136871 136875
235 284036
876 166267
410584 713330
256530 526265
254201 318223
8205 8211
367 403628
775 415545
587 333017
62171 286453
183011 183021
16 26
503 602407
361 873266
142 776661
848 760565
455 342446
546 351181
512 464303
26 243615
11 652217
272622 604005
38 547136
212455 618287
161155 161164
3673 3676
16 218776
363586 531764
104 143032
451 127680
543 400777
618646 618654
61325 110578
806447 806451
538 715082
114 154028
77776 77777
175 832667
60577 60581
35 656647
1 2
125035 125041
52676 81372
764 665688
510 748112
672637 672640
584 180368
175 734041
242 232618
411446 411447
1 1000000
157777 807542
164648 721412
647452 647456
236 667408
712816 785842
724 287221
230 135188
580 866011
2 3
586064 586066
433 625461
643 626773
743 768201
372 263516
628 347574
285 315232
523 751618
867 273842
274 518172
86113 86117
272 223700
340411 523315
213 813047
stdout
Standard output is empty