Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <ostream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int load()
  10. {
  11. fstream plik;
  12. double x[10];
  13. double y[10];
  14.  
  15. plik.open("s.txt", ios_base::in);
  16.  
  17. int n;
  18. plik >> n;
  19. char sep;
  20. for(int i = 0; i < n; i++)
  21. {
  22. plik >> x[i] >> sep >> y[i];
  23. cout << x[i] << " " << y[i] << endl;
  24. }
  25. }
  26.  
  27.  
  28. void zad1(int* a, int* b)
  29. {
  30. if(*b < *a)
  31. {
  32. int temp = *a;
  33. *a = *b;
  34. *b = temp;
  35. }
  36. }
  37.  
  38.  
  39. int mniej(int* a, int* b)
  40. {
  41. if(*a < *b)
  42. return *a;
  43. else
  44. return *b;
  45. }
  46.  
  47.  
  48. int* mniej2(int* a, int* b)
  49. {
  50. if(*a < *b)
  51. return a;
  52. else
  53. return b;
  54. }
  55.  
  56. double suma(double* a, int n)
  57. {
  58. double s = 0;
  59. for(int i = 0; i < n; i++)
  60. {
  61. s += *(a+i);
  62. }
  63. return s;
  64. }
  65.  
  66. int* MAX(int* tab, int n)
  67. {
  68. int c = 0;
  69. for(int i = 0; i < n; i++)
  70. {
  71. if(*(tab+c) < *(tab+i))
  72. c = i;
  73. }
  74. return tab+c;
  75. }
  76.  
  77. double* NewDouble()
  78. {
  79. return new double;
  80. }
  81.  
  82. double* NewTab(int Size)
  83. {
  84. return new double[Size];
  85. }
  86.  
  87. double* Copy(double* tab, int n)
  88. {
  89. double* res = new double[n];
  90. for(int i = 0; i < n; i++)
  91. {
  92. *(res+i) = *(tab+i);
  93. }
  94. return res;
  95. }
  96.  
  97. class Pierwsze
  98. {
  99. public:
  100. int* tab;
  101.  
  102.  
  103. Pierwsze()
  104. {
  105. tab = new int[10000];
  106. for(int i = 0; i < 10000; i++)
  107. {
  108. tab[i] = 0;
  109. }
  110. }
  111.  
  112. void Display()
  113. {
  114. for(int i = 0; i < 10000; i++)
  115. {
  116. if(tab[i] != 0)
  117. {
  118. cout << i << ": " << tab[i] << endl;
  119. }
  120. }
  121. }
  122.  
  123. /// n < 10 000
  124. void Rozklad(int n) /// rozklada n na liczby pierwsze
  125. {
  126. for(int i = 2; i <= n; i++)
  127. {
  128. while(n%i == 0)
  129. {
  130. n = n/i;
  131. tab[i]++;
  132. // cout << "dodaje+1 dla " << i << ", n=" << n*i << endl;
  133. }
  134.  
  135. }
  136. }
  137. };
  138.  
  139.  
  140.  
  141.  
  142.  
  143. int mainZAD1()
  144. {
  145. Pierwsze* results = new Pierwsze();
  146. int n = 10;
  147. n = 20;
  148. for(int i = 1; i <= n; i++)
  149. {
  150. results->Rozklad(i);
  151. }
  152. results->Display();
  153. }
  154.  
  155.  
  156.  
  157. class Slowo
  158. {
  159. public:
  160. string slowo;
  161. vector<int> wiersze;
  162.  
  163. Slowo(string slowo)
  164. {
  165. this->slowo = slowo;
  166. }
  167.  
  168. void DodajWiersz(int i)
  169. {
  170. for(int j = 0; j < wiersze.size(); j++)
  171. {
  172. if(wiersze[j] == i)
  173. return;
  174. }
  175. wiersze.push_back(i);
  176. }
  177.  
  178. void Display()
  179. {
  180. cout << slowo << " | wyst: ";
  181. for(int j = 0; j < wiersze.size(); j++)
  182. {
  183. cout << wiersze[j] << ", ";
  184. }
  185. cout << endl;
  186. }
  187. };
  188.  
  189. bool Contain(string s, vector<Slowo*> V)
  190. {
  191. for(int i = 0; i < V.size(); i++)
  192. {
  193. if(V[i]->slowo == s)
  194. return true;
  195. }
  196. return false;
  197. }
  198.  
  199. int getIndex(string s, vector<Slowo*> V)
  200. {
  201. for(int i = 0; i < V.size(); i++)
  202. {
  203. if(V[i]->slowo == s)
  204. if(V[i]->slowo == s)
  205. return i;
  206. }
  207. return -1;
  208. }
  209.  
  210. vector<string> split(string text)
  211. {
  212. cout << text << endl;
  213. vector<string> res;
  214.  
  215. string s = "";
  216. for(int i = 0; i < text.size(); i++)
  217. {
  218. if(text[i] != '.' && text[i] != ';' && text[i] != ':' && text[i] != ',')
  219. {
  220. if(text[i] != ' ')
  221. s += text[i];
  222. else
  223. {
  224. res.push_back(s);
  225. s = "";
  226. }
  227.  
  228. }
  229. }
  230. if(s != "")
  231. res.push_back(s);
  232. return res;
  233. }
  234.  
  235. int main()
  236. {
  237. vector<Slowo*> skorowidz;
  238.  
  239.  
  240. fstream plik;
  241. plik.open("dane.txt", ios_base::in);
  242.  
  243. string s;
  244. Slowo* slowo;
  245. vector<string> line;
  246. int nrLini = 0;
  247. int index;
  248. while( getline(plik, s) )
  249. {
  250. line = split(s);
  251. for(int i = 0; i < line.size(); i++)
  252. {
  253. cout << line[i] << endl;
  254. index = getIndex(line[i], skorowidz);
  255. if(index == -1)
  256. {
  257. slowo = new Slowo(line[i]);
  258. skorowidz.push_back(slowo);
  259. slowo->wiersze.push_back(nrLini);
  260. }
  261. else
  262. {
  263. skorowidz[index]->DodajWiersz(nrLini);
  264. }
  265. }
  266. nrLini++;
  267. }
  268. for(int i = 0; i < skorowidz.size(); i++)
  269. {
  270. skorowidz[i]->Display();
  271. }
  272. }
  273.  
  274.  
  275. int main2()
  276. {
  277. double* tab = NewTab(5);
  278. for(int i = 0; i < 5; i++)
  279. {
  280. tab[i] = 0.2;
  281. }
  282.  
  283. cout << suma( Copy(tab, 5) , 5) << endl;
  284.  
  285. int* a = new int(5);
  286. int* b = new int(1);
  287. cout << *a << endl;
  288. int c = mniej(a, b);
  289. cout << c << endl;
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement