Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. string print_first(int k) {
  7. int j;
  8. string s;
  9.  
  10. unsigned long long mask = 0;
  11. unsigned long long max_mask = pow(2, k);
  12. while(mask < max_mask) {
  13. unsigned long long ind = 1;
  14. ind <<= k - 1;
  15. for (j = 0; j < k; j++) {
  16. if (mask & ind) {
  17. cout << "4";
  18. } else {
  19. cout << "3";
  20. }
  21. ind >>= 1;
  22. }
  23. mask++;
  24. }
  25. }
  26.  
  27. void print_second(int k, string s) {
  28. int j;
  29. unsigned long long mask = 0;
  30. unsigned long long max_mask = pow(2, k);
  31. while(mask < max_mask) {
  32. cout << s;
  33. unsigned long long ind = 1;
  34. ind <<= k - 1;
  35. for (j = 0; j < k; j++) {
  36. if (mask & ind) {
  37. cout << "2";
  38. } else {
  39. cout << "1";
  40. }
  41. ind >>= 1;
  42. }
  43. cout << endl
  44. mask++;
  45. }
  46. }
  47.  
  48.  
  49.  
  50. int main()
  51. {
  52. int k;
  53. cin >> k;
  54. int i;
  55. for (i = 0; i <= k; i++) {
  56. print_first(i);
  57. }
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement