Advertisement
J00ker

Teze

Nov 20th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. //Suma nr imp
  6. int Impar(int a[], int n, int i)
  7. {
  8. if(i == n) return 0;
  9. if(n % 2 == 1) return a[i] + Impar(a, n, i+1);
  10. return 0 + Impar(a, n, i+1);
  11. }
  12.  
  13. //Elimin cif 0
  14. /*int Cif0(int n)
  15. {
  16. int s = 0, nr = 1;
  17. while(n)
  18. {
  19. if(n % 10 == 0)
  20. {
  21. ...
  22. }
  23. }
  24. }*/
  25.  
  26. //Fc. recurs. care afis. n in baza 2
  27. void Baza2(int n)
  28. {
  29. if (n > 0)
  30. {
  31. Baza2(n / 2);
  32. cout << n % 2;
  33. }
  34. }
  35.  
  36.  
  37.  
  38. int main()
  39. {
  40. Baza2(1024);
  41. return 0;
  42. }
  43.  
  44.  
  45. //t2
  46.  
  47. #include <iostream>
  48.  
  49. using namespace std;
  50.  
  51. int a[10001], k;
  52.  
  53. void Baza2(int n)
  54. {
  55. if (n > 0)
  56. {
  57. Baza2(n / 2);
  58. cout << n % 2;
  59. }
  60. }
  61.  
  62. void Citire_Vector(int n)
  63. {
  64. int i;
  65. for (i = 1; i <= n; i++)
  66. cin >> a[i];
  67. }
  68.  
  69. int Putere_Lui_2(int n)
  70. {
  71. int nr, k, i, d, j;
  72. nr = 0;
  73. for (i = 1; i <= n; i++)
  74. {
  75. d = 0;
  76. j = 0;
  77. k = (1 << j);
  78. while (a[i] >= k)
  79. {
  80. k = (1 << j);
  81. if (k == a[i])
  82. d = 1;
  83. j++;
  84. }
  85. if (d == 1)
  86. nr++;
  87. }
  88. return nr;
  89. }
  90.  
  91. void Sch(int &x, int &y)
  92. {
  93. int aux;
  94. aux = x;
  95. x = y;
  96. y = aux;
  97. }
  98.  
  99. int Pivot(int st, int dr)
  100. {
  101. int piv, i, j;
  102. piv = a[st];
  103. i = st + 1;
  104. j = dr;
  105. while (i < j)
  106. {
  107. if (a[i] < piv)
  108. i++;
  109. else if (a[j] > piv)
  110. j--;
  111. else if (i <= j a[i] > piv && piv > a[j])
  112. Sch(a[i], a[j]);
  113. }
  114. Sch(a[i-1], a[st]);
  115. return i - 1;
  116. }
  117.  
  118. int Kelement(int st, int dr, int k)
  119. {
  120. int m = Pivot(st, dr);
  121. if (m == k) return a[m];
  122. if ()
  123.  
  124. }
  125.  
  126. int main()
  127. {
  128. int n;
  129. /*cout << "N = ";
  130. cin >> n;
  131. Baza2(n);
  132. cout << "\n\n";
  133. cout << "N = ";
  134. cin >> n;
  135. Citire_Vector(n);
  136. cout << Putere_Lui_2(n) << "\n\n";*/
  137. cout << "K = ";
  138. cin >> k;
  139. cout << "N = ";
  140. cin >> n;
  141. Citire_Vector(n);
  142. cout << Pivot(1, n);
  143. for (int i = 1; i <= n; i++)
  144. cout << a[i] << " ";
  145. return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement