fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. unsigned long long int n = 21;
  10. unsigned long long int z = 0;
  11. unsigned long long int count = 0;
  12. string line;
  13. unsigned short int a=0, b=0, flag=0;
  14. for ( unsigned long long int k = 0; k<n; k++ ) {
  15.  
  16. z = pow(10, k);
  17. count = 0;
  18. for (unsigned long long int i = z; i<z*10; i++) {
  19. flag = 0;
  20. line = to_string(i);
  21. for (unsigned short int j = 0; j < line.length()-1; j++ ) {
  22. a = line[j];
  23. b = line[j+1];
  24. if ( abs(a - b) > 1 ) {
  25. flag++;
  26. break;
  27. }
  28. }
  29. if ( !flag ) count++;
  30. }
  31. cout << (k+1) << "=" << count << endl;
  32. }
  33.  
  34. return 0;
  35. }
Time limit exceeded #stdin #stdout 5s 3476KB
stdin
Standard input is empty
stdout
1=9
2=26
3=75
4=217
5=629
6=1826
7=5307