Guest User

Untitled

a guest
Oct 23rd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int *mas=new int[25];
  10. int N;
  11. cout << "Input N" << endl;
  12. cin >> N;
  13. int *p = new int[N];
  14. cout << "Input array" << endl;
  15. for (int i = 0; i < N; i++)
  16. {
  17. cin >> p[i];
  18. cout << i << " Element of array = " << p[i] << endl;
  19.  
  20. }
  21. for (int i = 0; i < N; i++)
  22. {
  23. if (p[i] == p[i + 1]||p[i]==p[i+i])
  24. {
  25. mas[i] = p[i];
  26. }
  27. }
  28. for (int i = 0; i < N; i++)
  29. {
  30. cout << mas[i];
  31. }
  32.  
  33. _getch();
  34. return 0;
  35. }
  36.  
  37. #include <iostream>
  38. #include <cstdlib>
  39. #include <ctime>
  40.  
  41. int main()
  42. {
  43. const size_t N = 10;
  44. int a[N];
  45.  
  46. std::srand( ( unsigned int )std::time( nullptr ) );
  47.  
  48. for ( auto &x : a ) x = std::rand() % N;
  49.  
  50. for ( auto x : a ) std::cout << x << ' ';
  51. std::cout << std::endl;
  52.  
  53. for ( size_t i = 0; i < N; i++ )
  54. {
  55. size_t j = 0;
  56. while ( j != i && a[j] != a[i] ) j++;
  57.  
  58. if ( j++ == i )
  59. {
  60. while ( j < N && a[j] != a[i] ) j++;
  61.  
  62. if ( j != N ) std::cout << a[i] << ' ';
  63. }
  64. }
  65. std::cout << std::endl;
  66.  
  67. return 0;
  68. }
  69.  
  70. 1 2 9 5 0 5 2 4 1 8
  71. 1 2 5
  72.  
  73. std::sort( a, a + N );
  74.  
  75. #include <algorithm>
  76.  
  77. #include <iostream>
  78. #include <cstdlib>
  79. #include <ctime>
  80. #include <algorithm>
  81.  
  82. int main()
  83. {
  84. const size_t N = 10;
  85. int a[N];
  86.  
  87. std::srand( ( unsigned int )std::time( nullptr ) );
  88.  
  89. for ( auto &x : a ) x = std::rand() % N;
  90.  
  91. for ( auto x : a ) std::cout << x << ' ';
  92. std::cout << std::endl;
  93.  
  94. std::sort( a, a + N );
  95.  
  96. for ( size_t i = 0; i < N; )
  97. {
  98. size_t j = i + 1;
  99.  
  100. while ( j < N && a[i] == a[j] ) j++;
  101.  
  102. if ( j - i > 1 )
  103. {
  104. std::cout << a[i] << ' ';
  105. }
  106.  
  107. i = j;
  108. }
  109. std::cout << std::endl;
  110.  
  111. return 0;
  112. }
  113.  
  114. for (int i = 0; i < N; i++)
  115. {
  116. if (p[i] == p[i + 1]||p[i]==p[i+i])
  117. {
  118. mas[i] = p[i];
  119. }
  120. }
  121.  
  122. if (p[i] == p[i + 1]||p[i]==p[i+i])
Add Comment
Please, Sign In to add comment