Advertisement
Guest User

7th

a guest
Dec 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int gr, i, cnt = 0;
  7. char textn [256], sm;
  8. bool lst = false, fst = false;
  9. char * sd;
  10.  
  11. int main ()
  12. {
  13.     cout << "Enter text : ";
  14.        cin.getline (tkst, 256);
  15.     cout << endl;
  16.  
  17.     cout << "New text : ";
  18.  
  19.     for (int i = 0; i <strlen (textn); i ++)
  20.     {
  21.         if (strlen (textn) - 1> i && i> 0)
  22.             cout << textn [i];
  23.         if (i == 0 || i == strlen (textn) - 1)
  24.             cout << "-";
  25.     }
  26.     cout << endl;
  27.  
  28. // 2
  29.  
  30.     cout << "Enter text : ";
  31.        cin.getline (tkst, 256);
  32.      sd = strtok (textn, "-;:,.! / @ &");
  33.  
  34.      while (sd != NULL)
  35.      {
  36.          cnt ++;
  37.          sd = strtok (NULL, "-;:,.! / @ &");
  38.      }
  39.      cout << '\n'
  40.           << "Words = " << cnt << endl;
  41.    
  42.      cout << endl;
  43. cnt = 0;
  44.  
  45. // 3
  46.  
  47.     cout << "Enter text : ";
  48.        cin.getline (tkst, 256);
  49.      for (i = 0; textn [i] != '\0'; i ++)
  50.      {
  51.          while (textn [i] != ' ' && textn [i] != '\0')
  52.          {
  53.              if (fst == false)
  54.              {
  55.                  sm = textn [i];
  56.              }
  57.              i ++;
  58.              fst = true;
  59.          }
  60.          if (textn [i] == ' ' || textn [i] == '\0')
  61.          {
  62.              lst = true;
  63.          }
  64.          if (lst == true)
  65.          {
  66.              if (textn [i - 1] == sm)
  67.              {
  68.                  cnt ++;
  69.              }
  70.          }
  71.          lst = false;
  72.          fst = false;
  73.      }
  74.      cout << "Words = " << cnt << endl;
  75.      cout << endl;
  76. cnt = 0;
  77.  
  78. //4
  79.  
  80.     cout << "Enter text : ";
  81.        cin.getline (tkst, 256);
  82.     cout << "Symbol : ";
  83.     cin >> sm;
  84.      for (i = 0; textn[i] != '\0'; i++)
  85.        {
  86.            while (textn[i] != ' ' && textn[i] != '\0')
  87.            {
  88.                i++;
  89.            }
  90.            if (textn[i] == ' ' || textn[i] == '\0')
  91.            {
  92.                lst = true;
  93.            }
  94.            if (lst == true)
  95.            {
  96.                if (textn[i - 1] == sm)
  97.                {
  98.                    cnt++;
  99.                }
  100.            }
  101.            lst = false;
  102.        }
  103.      cout << "Words =" << cnt << endl;
  104.    cin.ignore();
  105.      cout << endl;
  106.  
  107. //5
  108.  
  109.     cout << "Enter text : ";
  110.        cin.getline (tkst, 256);
  111.     cout << "Symbol : ";
  112.     cin >> sm;
  113.  
  114.     for (i = 0; textn[i] != '\0'; i++)
  115.     {
  116.         while (textn[i] != ' ' && textn[i] != '\0')
  117.         {
  118.             if (textn[i] == sm)
  119.             {
  120.                 gr = i;
  121.                 while (textn[gr] != '\0')
  122.                 {
  123.                     textn[gr] = textn[gr + 1];
  124.                     gr++;
  125.                 }
  126.             }
  127.             if (textn[i] != sm)
  128.                 i++;
  129.         }
  130.     }
  131.  
  132.     cout << "Text after removing = " << textn << endl;
  133.    
  134.     cout << endl;
  135.    delete [] sd;
  136.     cin.get();
  137.     system("pause");
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement