Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdexcept>
  4. #include <deque>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <functional>
  8. #include <vector>
  9. #include <set>
  10. #include "TestCurenja.h"
  11. using namespace std;
  12. double fun(double x)
  13. {
  14. return x*x;
  15. }
  16.  
  17.  
  18.  
  19. void Uradi(vector<int>&a)
  20. {
  21. int b(0);
  22. auto it(a.begin());
  23.  
  24. while(it!=a.end())
  25. {
  26. bool dal(true);
  27. int c(*it);
  28. int d(c%2);
  29. while(c!=0)
  30. {
  31. if(c%2!=d)dal=false;
  32. c=c/10;
  33.  
  34. }
  35. if(dal==false)
  36. {
  37. a[b]=*it;
  38.  
  39. b++;
  40. }
  41.  
  42.  
  43.  
  44. it++;
  45. }
  46. a.resize(b);
  47.  
  48.  
  49.  
  50. }
  51. bool DaLiJeTranzitivna(vector<vector<bool>>a)
  52. {
  53. bool jest(true);
  54. int i(a.size()),j(0),c(a[0].size());
  55. while(j<a.size())
  56. {
  57. if(c!=a[j].size())throw domain_error("Ovo nije matrica");
  58. if(i!=a[j].size())throw domain_error("Ovo nije matrica");
  59. j++;
  60. }
  61. i=0;
  62. j=0;
  63. c=0;
  64. while(i<a.size())
  65. {
  66.  
  67.  
  68.  
  69.  
  70. while(j<a.size())
  71. {
  72. int d(0);
  73. while(d<a.size())
  74. {
  75. if((a[i][j]=1)&&(a[j][d]=1))
  76. {
  77. if(a[i][j]!=a[i][d])jest=false;
  78.  
  79.  
  80. }
  81. d++;
  82. }
  83. j++;
  84. }
  85. i++;
  86. }
  87. return jest;
  88. }
  89. void Zamijeni(string &s, char znak)
  90. {
  91. auto it(s.begin());
  92. while(it!=s.end())
  93. {
  94.  
  95. if(*it==' ')*it=znak;
  96.  
  97. it++;
  98. }
  99.  
  100.  
  101. }
  102. template<typename zent,typename ako>
  103. zent Kontejner(zent &a,ako fun(ako))
  104. {
  105. zent b(a.size());
  106. auto it1(a.begin());
  107. auto it2(b.begin());
  108. while(it1!=a.end())
  109. {
  110. *it2=fun(*it1);
  111. it2++;
  112. it1++;
  113. }
  114. return b;
  115. }
  116. template<typename acc>
  117. acc fun(acc x)
  118. {
  119. return x*x;
  120. }
  121.  
  122.  
  123. int ** DinAlokacijao(int n)
  124. {
  125. int i(0);
  126. int **pok(nullptr);
  127. try
  128. {
  129. pok=new int *[n];
  130. while(i<n)
  131. {
  132. pok[i]=nullptr;
  133. pok[i]=new int[2*i+1];
  134. int c(i+1);
  135. int d(c);
  136. int k(0);
  137. if(i==0)
  138. {
  139. pok[i][k]=1;
  140. cout<<pok[i][k]<<endl;
  141.  
  142. }
  143. if(i!=0)
  144. {
  145.  
  146.  
  147. while(c!=0)
  148. {
  149. pok[i][k]=c;
  150. cout<<pok[i][k];
  151. c--;
  152. k++;
  153. }
  154. c=2;
  155.  
  156. while(c!=d+1)
  157. {
  158. pok[i][k]=c;
  159. cout<<pok[i][k];
  160. c++;
  161. }
  162. cout<<endl;
  163. }
  164. i++;
  165. }
  166.  
  167.  
  168. }
  169.  
  170. catch(...)
  171. {
  172. cout<<"Neuspjela alokacija";
  173. int i(0);
  174. while(i<n)
  175. {
  176. delete[]pok[i];
  177. i++;
  178. }
  179. delete[]pok;
  180.  
  181.  
  182.  
  183. }
  184.  
  185.  
  186. return pok;
  187. }
  188. int **DinoAlokacija(int n)
  189. {
  190. int **pok(nullptr);
  191. pok=new int *[n];
  192. pok[0]=new int[n*n];
  193.  
  194. int i(1);
  195. int o(1);
  196. while(i<n)
  197. {
  198. pok[i]=pok[i-1]+o;
  199. int c(i+1);
  200. int d(c);
  201. int j(0);
  202. if(i==0)
  203. {
  204. pok[i][j]=1;
  205. cout<<pok[i][j]<<endl;
  206.  
  207. }
  208. if(i!=0)
  209. {
  210.  
  211.  
  212. while(c!=0)
  213. {
  214. pok[i][j]=c;
  215. cout<<pok[i][j];
  216. c--;
  217. j++;
  218. }
  219. c=2;
  220.  
  221. while(c!=d+1)
  222. {
  223. pok[i][j]=c;
  224. cout<<pok[i][j];
  225. c++;
  226. }
  227. cout<<endl;
  228.  
  229.  
  230.  
  231.  
  232.  
  233. o=o+2;
  234.  
  235. i++;
  236. }
  237. }
  238.  
  239. return pok;
  240. }
  241.  
  242.  
  243. int main()
  244. {
  245. deque<int>a {};
  246. sort(a.begin(),a.end(),[](int x,int y)->bool
  247. {
  248. int prvi(0),drugi(0);
  249. int i(1);
  250. while(i<x)
  251. {
  252. if(x%i==0)prvi++;
  253. i++;
  254. }
  255. int j(1);
  256. while(j<y)
  257. {
  258. if(x%j==0)drugi++;
  259.  
  260. j++;
  261. }
  262. if(prvi>drugi)return true;
  263. if((prvi==drugi)&&(prvi<drugi))return true;
  264.  
  265. return false;
  266. });
  267. int n(5);
  268. auto it(DinoAlokacija(n));
  269.  
  270. int d(0);
  271. while(d<n)
  272. {
  273. delete[]it[d];
  274.  
  275. d++;
  276. }
  277.  
  278. delete[]it;
  279.  
  280. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement