Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4.  
  5. #define MAX_TEKSTO_ILGIS 100
  6. #define MAX_ZODZIO_ILGIS 100
  7.  
  8. void gautiDuomenis(std::string &tekstas);
  9. void ieskotiZodzio(std::string tekstas, std::string zodis);
  10. void ieskotiTrecioZodzio(std::string tekstas);
  11. void ieskotiAstuntosRaides(std::string tekstas, int zodzioSk);
  12. bool arRaide(char raide);
  13.  
  14. int main() {
  15.     std::string tekstas, zodis;
  16.     zodis = "printing";
  17.     int zodzioSk = 18;
  18.  
  19.     gautiDuomenis(tekstas);
  20.     //ieskotiZodzio(tekstas, zodis);
  21.     //ieskotiTrecioZodzio(tekstas);
  22.     ieskotiAstuntosRaides(tekstas, zodzioSk);
  23. }
  24.  
  25. void gautiDuomenis(std::string &tekstas) {
  26.     std::ifstream get;
  27.     get.open("tekstas.txt");
  28.  
  29.     tekstas.assign((std::istreambuf_iterator<char>(get)),
  30.                     std::istreambuf_iterator<char>());
  31.  
  32.     get.close();
  33. }
  34.  
  35. void ieskotiZodzio(std::string tekstas, std::string zodis) {
  36.     int tekstoIlgis = tekstas.length();
  37.     int zodzioIlgis = zodis.length();
  38.     int zodzioRaide = 0;
  39.  
  40.     bool radomZodzioPradzia = false;
  41.  
  42.     for (int i = 0; i < tekstoIlgis; i++) {
  43.         if (radomZodzioPradzia == true) {
  44.             if (tekstas[i] == zodis[zodzioRaide]) {
  45.                 zodzioRaide++;
  46.                 if (zodzioIlgis == zodzioRaide) {
  47.                     // zodzio pabaiga, paziuresim galune
  48.                     if (!arRaide(tekstas[i + 1])) {
  49.                         std::cout << "Zodis rastas" << std::endl;
  50.                         break;
  51.                     }
  52.                 }
  53.             } else {
  54.                 radomZodzioPradzia = false;
  55.             }
  56.         } else if (tekstas[i] == zodis[0]) {
  57.             radomZodzioPradzia = true;
  58.             zodzioRaide = 1;
  59.         }
  60.     }
  61. }
  62.  
  63. void ieskotiTrecioZodzio(std::string tekstas) {
  64.     int tekstoIlgis = tekstas.length();
  65.     int zodziai = 0;
  66.     bool prasidedaZodis = false;
  67.     bool ieskotiNaujosEilutes = false;
  68.     std::string zodis;
  69.  
  70.     for (int i = 0; i < tekstoIlgis; i++) {
  71.         if (prasidedaZodis == true) {
  72.             if (tekstas[i] == ' ') {
  73.                 std::cout << zodis << std::endl;
  74.                 prasidedaZodis = false;
  75.                 ieskotiNaujosEilutes = true;
  76.                 zodziai = -1;
  77.                 zodis = "";
  78.             } else {
  79.                 zodis += tekstas[i];
  80.             }
  81.         } else if (ieskotiNaujosEilutes == true) {
  82.             if (tekstas[i] == '.') {
  83.                 ieskotiNaujosEilutes = false;
  84.             }
  85.         } else {
  86.             if (tekstas[i] == ' ') {
  87.                 zodziai++;
  88.             }
  89.  
  90.             if (zodziai == 2) {
  91.                 prasidedaZodis = true;
  92.             }
  93.         }
  94.     }
  95. }
  96.  
  97. void ieskotiAstuntosRaides(std::string tekstas, int zodzioSk) {
  98.     int tekstoIlgis = tekstas.length();
  99.     int zodis = 1;
  100.     int raide = 0;
  101.     bool prasidedaZodis = false;
  102.  
  103.     for (int i = 0; i < tekstoIlgis; i++) {
  104.         if (tekstas[i] == ' ') {
  105.             zodis++;
  106.  
  107.             if (zodis == zodzioSk) {
  108.                 prasidedaZodis = true;
  109.             }
  110.         } else if (prasidedaZodis == true) {
  111.             if (arRaide(tekstas[i])) {
  112.                 raide++;
  113.  
  114.                 if (raide == 8) {
  115.                     std::cout << tekstas[i] << std::endl;
  116.                     break;
  117.                 }
  118.             } else {
  119.                 break;
  120.             }
  121.          }
  122.     }
  123. }
  124.  
  125. bool arRaide(char raide) {
  126.     std::string abecele = "abcdefghijklmnopqrstuvwxyz";
  127.  
  128.     return (abecele.find(raide) != std::string::npos);
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement