Advertisement
Guest User

Untitled

a guest
Dec 16th, 2012
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.90 KB | None | 0 0
  1. #pragma once
  2. #include <string>
  3. #include <fstream>
  4. #include <sstream>
  5. #include <iomanip>
  6. #include <map>
  7. #include "Knyga.h"
  8. using namespace std;
  9.  
  10. namespace Knygos {
  11.  
  12. using namespace System;
  13. using namespace System::ComponentModel;
  14. using namespace System::Collections;
  15. using namespace System::Windows::Forms;
  16. using namespace System::Data;
  17. using namespace System::Drawing;
  18.  
  19. /// <summary>
  20. /// Summary for Form1
  21. ///
  22. /// WARNING: If you change the name of this class, you will need to change the
  23. /// 'Resource File Name' property for the managed resource compiler tool
  24. /// associated with all .resx files this class depends on. Otherwise,
  25. /// the designers will not be able to interact properly with localized
  26. /// resources associated with this form.
  27. /// </summary>
  28. public ref class Form1 : public System::Windows::Forms::Form
  29. {
  30. public:
  31. Form1(void)
  32. {
  33. InitializeComponent();
  34. //
  35. //TODO: Add the constructor code here
  36. /* LD5S_3. Knygos
  37. Dviejuose tekstiniuose failuose Knyga1.txt ir Knyga2.txt duotas tekstas sudarytas iš žodžių,
  38. atskirtų skyrikliais. Skyriklių aibė žinoma ir abejuose failuose yra ta pati. Analizuojant tekstus,
  39. didžiosios ir mažosios raidės nesvarbios.
  40. Raskite, spausdinkite faile Analizė.txt ir išveskite ekrane teksto analizės rezultatus:
  41. ilgiausių žodžių, kuris yra abejuose failuose, sąrašą (ne daugiau nei 10 žodžių) ir jų
  42. pasikartojimo skaičių kiekviename iš failų; ilgiausių žodžių, kurie yra tik faile Knyga1.txt,
  43. bet nėra faile Knyga2.txt, sąrašą (ne daugiau nei 10 žodžių) ir jų pasikartojimo skaičių;
  44. Spausdinkite faile ManoKnyga.txt apjungtą tekstą, sudarytą pagal tokias taisykles:
  45. kopijuojamas pirmojo failo tekstas tol, kol sutinkamas pirmasis antrojo failo žodis
  46. arba pasiekiama failo pabaiga; kopijuojamas antrojo failo tekstas tol, kol sutinkamas pirmasis
  47. nenukopijuotas pirmojo failo žodis arba pasiekiama failo pabaiga; kartojama tol, kol pasiekiama
  48. abiejų failų pabaiga.*/
  49. //
  50. }
  51.  
  52. protected:
  53. /// <summary>
  54. /// Clean up any resources being used.
  55. /// </summary>
  56. ~Form1()
  57. {
  58. if (components)
  59. {
  60. delete components;
  61. }
  62. }
  63. private: System::Windows::Forms::TabControl^ tabControl1;
  64. protected:
  65. private: System::Windows::Forms::TabPage^ tabPage1;
  66. private: System::Windows::Forms::TabPage^ tabPage2;
  67.  
  68. private: System::Windows::Forms::TabPage^ tabPage3;
  69. private: System::Windows::Forms::TabPage^ tabPage4;
  70. private: System::Windows::Forms::MenuStrip^ menuStrip1;
  71. private: System::Windows::Forms::ToolStripMenuItem^ failasToolStripMenuItem;
  72. private: System::Windows::Forms::ToolStripMenuItem^ atidarytiPirmąFailąToolStripMenuItem;
  73. private: System::Windows::Forms::ToolStripMenuItem^ atidarytiAntrąFailąToolStripMenuItem;
  74. private: System::Windows::Forms::ToolStripMenuItem^ išsaugotiAnalizęToolStripMenuItem;
  75. private: System::Windows::Forms::ToolStripMenuItem^ išsaugotiKnygąToolStripMenuItem;
  76. private: System::Windows::Forms::ToolStripMenuItem^ uždarytiToolStripMenuItem;
  77. private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
  78. private: System::Windows::Forms::OpenFileDialog^ openFileDialog2;
  79. private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
  80. private: System::Windows::Forms::SaveFileDialog^ saveFileDialog2;
  81.  
  82. private:
  83. /// <summary>
  84. /// Required designer variable.
  85.  
  86. String^ dfv1;
  87. String^ dfv2;
  88. String^ rfv1;
  89. String^ rfv2;
  90. Knyga * Kn1;
  91. Knyga * Kn2;
  92. ///
  93.  
  94. private: System::Windows::Forms::RichTextBox^ richTextBox1;
  95. private: System::Windows::Forms::RichTextBox^ richTextBox2;
  96. private: System::Windows::Forms::RichTextBox^ richTextBox3;
  97. private: System::Windows::Forms::RichTextBox^ richTextBox4;
  98. private: System::Windows::Forms::ToolStripMenuItem^ funkcijosToolStripMenuItem;
  99. private: System::Windows::Forms::ToolStripMenuItem^ analizėToolStripMenuItem;
  100. private: System::Windows::Forms::ToolStripMenuItem^ jungtiTekstusToolStripMenuItem;
  101. private: System::Windows::Forms::Label^ label1;
  102. private: System::Windows::Forms::TextBox^ textBox1;
  103.  
  104. /// </summary>
  105. System::ComponentModel::Container ^components;
  106.  
  107. #pragma region Windows Form Designer generated code
  108. /// <summary>
  109. /// Required method for Designer support - do not modify
  110. /// the contents of this method with the code editor.
  111. /// </summary>
  112. void InitializeComponent(void)
  113. {
  114. this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
  115. this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
  116. this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
  117. this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
  118. this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
  119. this->tabPage3 = (gcnew System::Windows::Forms::TabPage());
  120. this->richTextBox3 = (gcnew System::Windows::Forms::RichTextBox());
  121. this->tabPage4 = (gcnew System::Windows::Forms::TabPage());
  122. this->richTextBox4 = (gcnew System::Windows::Forms::RichTextBox());
  123. this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
  124. this->failasToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  125. this->atidarytiPirmąFailąToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  126. this->atidarytiAntrąFailąToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  127. this->išsaugotiAnalizęToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  128. this->išsaugotiKnygąToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  129. this->uždarytiToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  130. this->funkcijosToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  131. this->analizėToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  132. this->jungtiTekstusToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  133. this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
  134. this->openFileDialog2 = (gcnew System::Windows::Forms::OpenFileDialog());
  135. this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
  136. this->saveFileDialog2 = (gcnew System::Windows::Forms::SaveFileDialog());
  137. this->label1 = (gcnew System::Windows::Forms::Label());
  138. this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  139. this->tabControl1->SuspendLayout();
  140. this->tabPage1->SuspendLayout();
  141. this->tabPage2->SuspendLayout();
  142. this->tabPage3->SuspendLayout();
  143. this->tabPage4->SuspendLayout();
  144. this->menuStrip1->SuspendLayout();
  145. this->SuspendLayout();
  146. //
  147. // tabControl1
  148. //
  149. this->tabControl1->Controls->Add(this->tabPage1);
  150. this->tabControl1->Controls->Add(this->tabPage2);
  151. this->tabControl1->Controls->Add(this->tabPage3);
  152. this->tabControl1->Controls->Add(this->tabPage4);
  153. this->tabControl1->Location = System::Drawing::Point(-2, 27);
  154. this->tabControl1->Name = L"tabControl1";
  155. this->tabControl1->SelectedIndex = 0;
  156. this->tabControl1->Size = System::Drawing::Size(810, 314);
  157. this->tabControl1->TabIndex = 0;
  158. //
  159. // tabPage1
  160. //
  161. this->tabPage1->Controls->Add(this->richTextBox1);
  162. this->tabPage1->Location = System::Drawing::Point(4, 22);
  163. this->tabPage1->Name = L"tabPage1";
  164. this->tabPage1->Padding = System::Windows::Forms::Padding(3);
  165. this->tabPage1->Size = System::Drawing::Size(713, 288);
  166. this->tabPage1->TabIndex = 0;
  167. this->tabPage1->Text = L"Pirma knyga";
  168. this->tabPage1->UseVisualStyleBackColor = true;
  169. //
  170. // richTextBox1
  171. //
  172. this->richTextBox1->Dock = System::Windows::Forms::DockStyle::Fill;
  173. this->richTextBox1->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  174. static_cast<System::Byte>(186)));
  175. this->richTextBox1->Location = System::Drawing::Point(3, 3);
  176. this->richTextBox1->Name = L"richTextBox1";
  177. this->richTextBox1->Size = System::Drawing::Size(707, 282);
  178. this->richTextBox1->TabIndex = 0;
  179. this->richTextBox1->Text = L"";
  180. //
  181. // tabPage2
  182. //
  183. this->tabPage2->Controls->Add(this->richTextBox2);
  184. this->tabPage2->Location = System::Drawing::Point(4, 22);
  185. this->tabPage2->Name = L"tabPage2";
  186. this->tabPage2->Padding = System::Windows::Forms::Padding(3);
  187. this->tabPage2->Size = System::Drawing::Size(713, 288);
  188. this->tabPage2->TabIndex = 1;
  189. this->tabPage2->Text = L"Antra knyga";
  190. this->tabPage2->UseVisualStyleBackColor = true;
  191. //
  192. // richTextBox2
  193. //
  194. this->richTextBox2->Dock = System::Windows::Forms::DockStyle::Fill;
  195. this->richTextBox2->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  196. static_cast<System::Byte>(186)));
  197. this->richTextBox2->Location = System::Drawing::Point(3, 3);
  198. this->richTextBox2->Name = L"richTextBox2";
  199. this->richTextBox2->Size = System::Drawing::Size(707, 282);
  200. this->richTextBox2->TabIndex = 0;
  201. this->richTextBox2->Text = L"";
  202. //
  203. // tabPage3
  204. //
  205. this->tabPage3->Controls->Add(this->richTextBox3);
  206. this->tabPage3->Location = System::Drawing::Point(4, 22);
  207. this->tabPage3->Name = L"tabPage3";
  208. this->tabPage3->Padding = System::Windows::Forms::Padding(3);
  209. this->tabPage3->Size = System::Drawing::Size(713, 288);
  210. this->tabPage3->TabIndex = 2;
  211. this->tabPage3->Text = L"Analizė";
  212. this->tabPage3->UseVisualStyleBackColor = true;
  213. //
  214. // richTextBox3
  215. //
  216. this->richTextBox3->Dock = System::Windows::Forms::DockStyle::Fill;
  217. this->richTextBox3->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  218. static_cast<System::Byte>(186)));
  219. this->richTextBox3->Location = System::Drawing::Point(3, 3);
  220. this->richTextBox3->Name = L"richTextBox3";
  221. this->richTextBox3->Size = System::Drawing::Size(707, 282);
  222. this->richTextBox3->TabIndex = 0;
  223. this->richTextBox3->Text = L"";
  224. //
  225. // tabPage4
  226. //
  227. this->tabPage4->Controls->Add(this->richTextBox4);
  228. this->tabPage4->Location = System::Drawing::Point(4, 22);
  229. this->tabPage4->Name = L"tabPage4";
  230. this->tabPage4->Padding = System::Windows::Forms::Padding(3);
  231. this->tabPage4->Size = System::Drawing::Size(802, 288);
  232. this->tabPage4->TabIndex = 3;
  233. this->tabPage4->Text = L"Mano knyga";
  234. this->tabPage4->UseVisualStyleBackColor = true;
  235. //
  236. // richTextBox4
  237. //
  238. this->richTextBox4->Dock = System::Windows::Forms::DockStyle::Fill;
  239. this->richTextBox4->Font = (gcnew System::Drawing::Font(L"Courier New", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  240. static_cast<System::Byte>(186)));
  241. this->richTextBox4->Location = System::Drawing::Point(3, 3);
  242. this->richTextBox4->Name = L"richTextBox4";
  243. this->richTextBox4->Size = System::Drawing::Size(796, 282);
  244. this->richTextBox4->TabIndex = 0;
  245. this->richTextBox4->Text = L"";
  246. //
  247. // menuStrip1
  248. //
  249. this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->failasToolStripMenuItem,
  250. this->funkcijosToolStripMenuItem});
  251. this->menuStrip1->Location = System::Drawing::Point(0, 0);
  252. this->menuStrip1->Name = L"menuStrip1";
  253. this->menuStrip1->Size = System::Drawing::Size(834, 24);
  254. this->menuStrip1->TabIndex = 1;
  255. this->menuStrip1->Text = L"menuStrip1";
  256. //
  257. // failasToolStripMenuItem
  258. //
  259. this->failasToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(5) {this->atidarytiPirmąFailąToolStripMenuItem,
  260. this->atidarytiAntrąFailąToolStripMenuItem, this->išsaugotiAnalizęToolStripMenuItem, this->išsaugotiKnygąToolStripMenuItem, this->uždarytiToolStripMenuItem});
  261. this->failasToolStripMenuItem->Name = L"failasToolStripMenuItem";
  262. this->failasToolStripMenuItem->Size = System::Drawing::Size(48, 20);
  263. this->failasToolStripMenuItem->Text = L"Failas";
  264. //
  265. // atidarytiPirmąFailąToolStripMenuItem
  266. //
  267. this->atidarytiPirmąFailąToolStripMenuItem->Name = L"atidarytiPirmąFailąToolStripMenuItem";
  268. this->atidarytiPirmąFailąToolStripMenuItem->Size = System::Drawing::Size(178, 22);
  269. this->atidarytiPirmąFailąToolStripMenuItem->Text = L"Atidaryti pirmą failą";
  270. this->atidarytiPirmąFailąToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::atidarytiPirmąFailąToolStripMenuItem_Click);
  271. //
  272. // atidarytiAntrąFailąToolStripMenuItem
  273. //
  274. this->atidarytiAntrąFailąToolStripMenuItem->Name = L"atidarytiAntrąFailąToolStripMenuItem";
  275. this->atidarytiAntrąFailąToolStripMenuItem->Size = System::Drawing::Size(178, 22);
  276. this->atidarytiAntrąFailąToolStripMenuItem->Text = L"Atidaryti antrą failą";
  277. this->atidarytiAntrąFailąToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::atidarytiAntrąFailąToolStripMenuItem_Click);
  278. //
  279. // išsaugotiAnalizęToolStripMenuItem
  280. //
  281. this->išsaugotiAnalizęToolStripMenuItem->Name = L"išsaugotiAnalizęToolStripMenuItem";
  282. this->išsaugotiAnalizęToolStripMenuItem->Size = System::Drawing::Size(178, 22);
  283. this->išsaugotiAnalizęToolStripMenuItem->Text = L"Išsaugoti analizę";
  284. //
  285. // išsaugotiKnygąToolStripMenuItem
  286. //
  287. this->išsaugotiKnygąToolStripMenuItem->Name = L"išsaugotiKnygąToolStripMenuItem";
  288. this->išsaugotiKnygąToolStripMenuItem->Size = System::Drawing::Size(178, 22);
  289. this->išsaugotiKnygąToolStripMenuItem->Text = L"Išsaugoti knygą";
  290. //
  291. // uždarytiToolStripMenuItem
  292. //
  293. this->uždarytiToolStripMenuItem->Name = L"uždarytiToolStripMenuItem";
  294. this->uždarytiToolStripMenuItem->Size = System::Drawing::Size(178, 22);
  295. this->uždarytiToolStripMenuItem->Text = L"Uždaryti";
  296. this->uždarytiToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::uždarytiToolStripMenuItem_Click);
  297. //
  298. // funkcijosToolStripMenuItem
  299. //
  300. this->funkcijosToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {this->analizėToolStripMenuItem,
  301. this->jungtiTekstusToolStripMenuItem});
  302. this->funkcijosToolStripMenuItem->Name = L"funkcijosToolStripMenuItem";
  303. this->funkcijosToolStripMenuItem->Size = System::Drawing::Size(69, 20);
  304. this->funkcijosToolStripMenuItem->Text = L"Funkcijos";
  305. //
  306. // analizėToolStripMenuItem
  307. //
  308. this->analizėToolStripMenuItem->Name = L"analizėToolStripMenuItem";
  309. this->analizėToolStripMenuItem->Size = System::Drawing::Size(146, 22);
  310. this->analizėToolStripMenuItem->Text = L"Analizė";
  311. this->analizėToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::analizėToolStripMenuItem_Click);
  312. //
  313. // jungtiTekstusToolStripMenuItem
  314. //
  315. this->jungtiTekstusToolStripMenuItem->Name = L"jungtiTekstusToolStripMenuItem";
  316. this->jungtiTekstusToolStripMenuItem->Size = System::Drawing::Size(146, 22);
  317. this->jungtiTekstusToolStripMenuItem->Text = L"Jungti tekstus";
  318. this->jungtiTekstusToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::jungtiTekstusToolStripMenuItem_Click);
  319. //
  320. // openFileDialog1
  321. //
  322. this->openFileDialog1->FileName = L"openFileDialog1";
  323. //
  324. // openFileDialog2
  325. //
  326. this->openFileDialog2->FileName = L"openFileDialog2";
  327. //
  328. // label1
  329. //
  330. this->label1->AutoSize = true;
  331. this->label1->Location = System::Drawing::Point(29, 356);
  332. this->label1->Name = L"label1";
  333. this->label1->Size = System::Drawing::Size(51, 13);
  334. this->label1->TabIndex = 2;
  335. this->label1->Text = L"Skyrikliai:";
  336. //
  337. // textBox1
  338. //
  339. this->textBox1->Location = System::Drawing::Point(107, 353);
  340. this->textBox1->Name = L"textBox1";
  341. this->textBox1->Size = System::Drawing::Size(100, 20);
  342. this->textBox1->TabIndex = 3;
  343. this->textBox1->Text = L" .,;:!\?\'\"-()<>[]";
  344. //
  345. // Form1
  346. //
  347. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  348. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  349. this->ClientSize = System::Drawing::Size(834, 378);
  350. this->Controls->Add(this->textBox1);
  351. this->Controls->Add(this->label1);
  352. this->Controls->Add(this->tabControl1);
  353. this->Controls->Add(this->menuStrip1);
  354. this->MainMenuStrip = this->menuStrip1;
  355. this->Name = L"Form1";
  356. this->Text = L"Form1";
  357. this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
  358. this->tabControl1->ResumeLayout(false);
  359. this->tabPage1->ResumeLayout(false);
  360. this->tabPage2->ResumeLayout(false);
  361. this->tabPage3->ResumeLayout(false);
  362. this->tabPage4->ResumeLayout(false);
  363. this->menuStrip1->ResumeLayout(false);
  364. this->menuStrip1->PerformLayout();
  365. this->ResumeLayout(false);
  366. this->PerformLayout();
  367.  
  368. }
  369. #pragma endregion
  370. void Stringtostring(String^ s, string & os)
  371. {
  372. using namespace System::Runtime::InteropServices;
  373. const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
  374. os = chars;
  375. Marshal::FreeHGlobal(IntPtr((void*)chars));
  376. }
  377. void Skaityti(const char fv[], Knyga & Kn)
  378. {
  379. string eil;
  380. ifstream fd(fv);
  381. while(!fd.eof())
  382. {
  383. getline(fd, eil);
  384. Kn.DetiEilute(eil);
  385. }
  386. fd.close();
  387. }
  388. unsigned int RastiIlgi(Knyga & Kn, string & skyrikliai)
  389. {
  390. string zodis;
  391. string eilute;
  392. unsigned int max = 0;
  393. for(int i = 0; i < Kn.ImtiEilKiek(); i++)
  394. {
  395. eilute = Kn.ImtiEilute(i);
  396. size_t paskPoz = eilute.find_first_not_of(skyrikliai, 0);
  397. size_t poz = eilute.find_first_of(skyrikliai, paskPoz);
  398. while (string::npos != poz || string::npos != paskPoz)
  399. {
  400. zodis = eilute.substr(paskPoz, poz - paskPoz);
  401. if(zodis.length() > max)
  402. max = zodis.length();
  403. paskPoz = eilute.find_first_not_of(skyrikliai, poz);
  404. poz = eilute.find_first_of(skyrikliai, paskPoz);
  405. }
  406. }
  407. return max;
  408. }
  409. void RinktiPagalIlgi(map<string, int> & Ilgiausi, Knyga & Kn, int max, string skyrikliai)
  410. {
  411. Ilgiausi.clear();
  412. string eilute;
  413. string zodis;
  414. for(int i = 0; i < Kn.ImtiEilKiek(); i++)
  415. {
  416. eilute = Kn.ImtiEilute(i);
  417. size_t paskPoz = eilute.find_first_not_of(skyrikliai, 0);
  418. size_t poz = eilute.find_first_of(skyrikliai, paskPoz);
  419. while (string::npos != poz || string::npos != paskPoz)
  420. {
  421. if(poz - paskPoz == max)
  422. {
  423. zodis = eilute.substr(paskPoz, poz - paskPoz);
  424. for(int i = 0; i < zodis.size(); i++)
  425. zodis[i] = tolower(zodis[i]);
  426. Ilgiausi[zodis]? Ilgiausi[zodis]++ : Ilgiausi[zodis]=1;
  427. }
  428. paskPoz = eilute.find_first_not_of(skyrikliai, poz);
  429. poz = eilute.find_first_of(skyrikliai, paskPoz);
  430. }
  431. }
  432. }
  433. void BendruRadimas(map<string, int> & Bendri, map<string, int> & Ilgiausi1, map<string, int> & Ilgiausi2)
  434. {
  435. for (std::map<string, int>::iterator it1 = Ilgiausi1.begin(); it1 != Ilgiausi1.end(); ++it1)
  436. for (std::map<string, int>::iterator it2 = Ilgiausi2.begin(); it2 != Ilgiausi2.end(); ++it2)
  437. {
  438.  
  439. if(it1->first == it2->first)
  440. {
  441. Bendri[it1->first] = it1->second + it2->second;
  442. break;
  443. }
  444. }
  445. }
  446. void SkirtinguRadimas(map<string, int> & Nesikart, map<string, int> & Ilgiausi1, map<string, int> & Ilgiausi2)
  447. {
  448. for (std::map<string, int>::iterator it1 = Ilgiausi1.begin(); it1 != Ilgiausi1.end(); ++it1)
  449. {
  450. bool kartojasi = false;
  451. for (std::map<string, int>::iterator it2 = Ilgiausi2.begin(); it2 != Ilgiausi2.end(); ++it2)
  452. {
  453. if(it1->first == it2->first)
  454. {
  455. kartojasi = true;
  456. break;
  457. }
  458. }
  459. if(kartojasi == false)
  460. Nesikart[it1->first] = it1->second;
  461. }
  462. }
  463. void RinktiIlgiausius(map<string, int> & Bendri, map<string, int> & Nesikart, Knyga & Kn1, Knyga & Kn2, string & skyrikliai)
  464. {
  465. map<string, int> Ilgiausi1;
  466. map<string, int> Ilgiausi2;
  467. int max = RastiIlgi(Kn1, skyrikliai);
  468. while((Bendri.size() == 0 || Nesikart.size() == 0) && max != 0)
  469. {
  470. RinktiPagalIlgi(Ilgiausi1, Kn1, max, skyrikliai);
  471. RinktiPagalIlgi(Ilgiausi2, Kn2, max, skyrikliai);
  472. if(Bendri.size() == 0)
  473. BendruRadimas(Bendri, Ilgiausi1, Ilgiausi2);
  474. if(Nesikart.size() == 0)
  475. SkirtinguRadimas(Nesikart, Ilgiausi1, Ilgiausi2);
  476. max--;
  477. }
  478. }
  479. void SpausdintiAnalize(const char fv[], string antraste, map<string, int> Sarasas)
  480. {
  481. ofstream fr(fv, ios::app);
  482. fr << antraste << endl;
  483. fr << "-------------------------------------------" << endl;
  484. fr << "|" << setw(30) << "Žodis" << " |" << setw(8) << "Dažnis" << " |" << endl;
  485. fr << "-------------------------------------------" << endl;
  486. for(map<string, int>::iterator it = Sarasas.begin(); it != Sarasas.end(); ++it)
  487. fr << "|" << setw(30) << it->first << " |" << setw(8) << it->second << " |" << endl;
  488. fr << "-------------------------------------------" << endl;
  489. fr << endl;
  490. fr.close();
  491. }
  492. void Jungti(Knyga & ManoKnyga, Knyga & Kn1, Knyga & Kn2, string skyrikliai)
  493. {
  494. stringstream eilute;
  495. string zodis1, zodis2;
  496. string eil1 = Kn1.ImtiEilute(0);
  497. eil1 += " ";
  498. eil1.erase(0, eil1.find_first_not_of(skyrikliai, 0));
  499. string eil2 = Kn2.ImtiEilute(0);
  500. eil2 += " ";
  501. eil2.erase(0, eil2.find_first_not_of(skyrikliai, 0));
  502. int akt1 = 0, akt2 = 0;
  503. int poz, skPoz;
  504. while(akt1 < Kn1.ImtiEilKiek() && akt2 < Kn2.ImtiEilKiek())
  505. {
  506. while(akt1 < Kn1.ImtiEilKiek() - 1)
  507. {
  508. if(eil1.size() == 0)
  509. {
  510. akt1++;
  511. eil1 = Kn1.ImtiEilute(akt1);
  512. eil1 += " ";
  513. if(akt1 < Kn1.ImtiEilKiek() - 1)
  514. break;
  515. }
  516. if(eilute.str().size() > 60)
  517. {
  518. ManoKnyga.DetiEilute(eilute.str());
  519. eilute.str("");
  520. }
  521. skPoz = eil1.find_first_of(skyrikliai, 0);
  522. poz = eil1.find_first_not_of(skyrikliai, 0);
  523. if(skPoz < poz)
  524. {
  525. eilute << eil1.substr(0, poz);
  526. eil1.erase(0, poz);
  527. }
  528. else
  529. {
  530. zodis1 = eil1.substr(0, skPoz);
  531. eil1.erase(0, skPoz);
  532. eilute << zodis1;
  533. for(int i = 0; i < zodis1.size(); i++)
  534. zodis1[i] = tolower(zodis1[i]);
  535. zodis2 = eil2.substr(0, skPoz);
  536. for(int i = 0; i < zodis2.size(); i++)
  537. zodis2[i] = tolower(zodis2[i]);
  538. if(zodis1 == zodis2)
  539. {
  540. poz = eil1.find_first_not_of(skyrikliai, 0);
  541. eil1.erase(0, poz);
  542. skPoz = eil2.find_first_of(skyrikliai, 0);
  543. eil2.erase(0, skPoz);
  544. break;
  545. }
  546. }
  547. }
  548. while(akt2 < Kn2.ImtiEilKiek() - 1)
  549. {
  550. if(eil2.size() == 0)
  551. {
  552. akt2++;
  553. eil2 = Kn2.ImtiEilute(akt2);
  554. eil2 += " ";
  555. if(akt2 < Kn2.ImtiEilKiek() - 1)
  556. break;
  557. }
  558. if(eilute.str().size() > 60)
  559. {
  560. ManoKnyga.DetiEilute(eilute.str());
  561. eilute.str("");
  562. }
  563. skPoz = eil2.find_first_of(skyrikliai, 0);
  564. poz = eil2.find_first_not_of(skyrikliai, 0);
  565. if(skPoz < poz)
  566. {
  567. eilute << eil2.substr(0, poz);
  568. eil2.erase(0, poz);
  569. }
  570. else
  571. {
  572. zodis2 = eil2.substr(0, skPoz);
  573. eil2.erase(0, skPoz);
  574. eilute << zodis2;
  575. for(int i = 0; i < zodis2.size(); i++)
  576. zodis2[i] = tolower(zodis2[i]);
  577. zodis1 = eil1.substr(0, skPoz);
  578. for(int i = 0; i < zodis1.size(); i++)
  579. zodis1[i] = tolower(zodis1[i]);
  580. if(zodis2 == zodis1)
  581. {
  582. poz = eil2.find_first_not_of(skyrikliai, 0);
  583. eil2.erase(0, poz);
  584. skPoz = eil1.find_first_of(skyrikliai, 0);
  585. eil1.erase(0, skPoz);
  586. break;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
  593. setlocale(LC_ALL, "Lithuanian");
  594. }
  595. private: System::Void atidarytiPirmąFailąToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  596. openFileDialog1->DefaultExt = ".txt";
  597. openFileDialog1->Filter = "TXT failai | *.txt";
  598. if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
  599. openFileDialog1->FileName->Length > 0)
  600. {
  601. dfv1 = openFileDialog1->FileName;
  602. richTextBox1->LoadFile(dfv1, RichTextBoxStreamType::PlainText);
  603. string dfvs1;
  604. Kn1 = new Knyga;
  605. Stringtostring(dfv1, dfvs1);
  606. Skaityti(dfvs1.c_str(), *Kn1);
  607. }
  608. }
  609. private: System::Void atidarytiAntrąFailąToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  610. openFileDialog2->DefaultExt = ".txt";
  611. openFileDialog2->Filter = "TXT failai | *.txt";
  612. if(openFileDialog2->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
  613. openFileDialog2->FileName->Length > 0)
  614. {
  615. dfv2 = openFileDialog2->FileName;
  616. richTextBox2->LoadFile(dfv2, RichTextBoxStreamType::PlainText);
  617. string dfvs2;
  618. Kn2 = new Knyga;
  619. Stringtostring(dfv2, dfvs2);
  620. Skaityti(dfvs2.c_str(), *Kn2);
  621. }
  622. }
  623. private: System::Void uždarytiToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  624. exit(0);
  625. }
  626. private: System::Void analizėToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  627. const char fv[] = "Analize.txt";
  628. ofstream fr(fv);
  629. fr.close();
  630. String^ skyrikliaiS = "";
  631. string skyrikliai;
  632. skyrikliaiS = textBox1->Text->ToString();
  633. Stringtostring(skyrikliaiS, skyrikliai);
  634. skyrikliai[skyrikliai.size()] = '\n';
  635. map<string, int> Bendri;
  636. map<string, int> Nesikart;
  637. RinktiIlgiausius(Bendri, Nesikart, *Kn1, *Kn2, skyrikliai);
  638. SpausdintiAnalize(fv, "Ilgiausi bendri žodžiai:", Bendri);
  639. SpausdintiAnalize(fv, "Ilgiausi ir tik pirmoje knygoje esantys žodžiai:", Nesikart);
  640. richTextBox3->LoadFile("Analize.txt", RichTextBoxStreamType::PlainText);
  641. }
  642. private: System::Void jungtiTekstusToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  643. stringstream eil;
  644. String^ skyrikliaiS = "";
  645. string skyrikliai;
  646. skyrikliaiS = textBox1->Text->ToString();
  647. Stringtostring(skyrikliaiS, skyrikliai);
  648. skyrikliai[skyrikliai.size()] = '\n';
  649. const char fv[] = "ManoKnyga.txt";
  650. Knyga ManoKnyga;
  651. Jungti(ManoKnyga, *Kn1, *Kn2, skyrikliai);
  652. }
  653. };
  654. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement