Advertisement
tantarin

Untitled

Jun 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5. //индексация с нуля
  6. int main()
  7. { vector <int> data = {0,0,0,0,0};
  8. int n =4,radix = 3,idx=0,cnt=1,j,k;
  9. cin>>idx;
  10. label:
  11. while (cnt <= pow(radix, n)){//1<=81
  12. cnt = cnt +1; //cnt=2 cnt=3
  13. j = n;//j = 4
  14. label1:
  15. if(j >=1){ //4>1
  16. if(data[j]<radix-1){//0<2
  17. data[j] = data[j]+1;//data[4] = 1
  18.  
  19. if(j<n && (data[j+1] == (radix -1))){
  20. k = j+1;
  21. while(k<=n){
  22. data[k] =0;
  23. k = k+1;
  24. }}
  25.  
  26. if(cnt == idx) {
  27. for(int c:data) cout << c <<' ';
  28. cout<<endl;
  29. return 0;
  30. }
  31. else goto label;
  32. }
  33. else {j = j-1;
  34.     goto label1;
  35. }//3
  36.  
  37. }
  38. else goto  label;
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement