Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. void splitter(int *addres, int number)
  8. {
  9. int splitter = 1000;
  10. int ost = 10;
  11.  
  12. for (int i = 0; i < 4; i++)
  13. {
  14. addres[i] = (number / splitter) % ost;
  15. splitter /= 10;
  16. }
  17. }
  18.  
  19. void popFromArr(int *addres, int size, int popUpNum)
  20. {
  21. int *newArr = new int[size - 1];
  22. int realIndex = 0;
  23. for (int i = 0; i < (size - 1); i++)
  24. {
  25. if (addres[i] != popUpNum)
  26. {
  27. newArr[realIndex] = addres[i];
  28. realIndex++;
  29. }
  30. }
  31. addres = newArr;
  32. }
  33.  
  34. void randomizeNumber(int *addres)
  35. {
  36. int *avArr = new int[10];
  37.  
  38. for (int i = 0; i < 10; i++)
  39. {
  40. avArr[i] = i;
  41. }
  42.  
  43. for (int i = 0; i < 4; i++)
  44. {
  45. int selectedIndex = (rand() % (10 - i));
  46. addres[i] = avArr[selectedIndex];
  47. popFromArr(addres, (10 - i), avArr[selectedIndex]);
  48. }
  49. }
  50.  
  51. int main()
  52. {
  53. int randNum[4];
  54. int input[4] = { 0,0,0,0 };
  55. randomizeNumber(randNum);
  56.  
  57. while (true)
  58. {
  59. int inputT;
  60. cin >> inputT;
  61. splitter(input, inputT);
  62. cout << input[0] << input[1] << input[2] << input[3] << endl;
  63. cout << randNum[0] << randNum[1] << randNum[2] << randNum[3] << endl;
  64.  
  65.  
  66. }
  67.  
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement