Advertisement
Guest User

Removing one letter

a guest
Sep 22nd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <string>
  4. #include <stdio.h>
  5. #include <algorithm>
  6. #include <iterator>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     setlocale(LC_ALL, "rus");
  13.  
  14.     string first, second;
  15.     bool temp1 = false, temp2 = false;
  16.  
  17.     cout << "Пожалуйста, введите первое слово с ошибкой: ";
  18.     cin >> first;
  19.     cout << "Пожалуйста, введите второе слово без ошибки на один символ меньше: ";
  20.     cin >> second;
  21.  
  22.     int f = first.length() - 1;
  23.     int s = second.length();
  24.    
  25.     cout << "Первое слово: " + first << endl;
  26.     cout << "Второе слово: " + second << endl;
  27.     cout << "Длина первого слова: " <<  first.length() << endl;
  28.     cout << "Длина второго слова: " << second.length() << endl;
  29.  
  30.     for (int i = 0; i < (int)first.length(); i++) {
  31.         if (isalpha(first[i])) {
  32.             temp1 = true;                      
  33.         }
  34.         else
  35.         {
  36.             temp1 = false;
  37.             break;
  38.         }
  39.     }
  40.  
  41.     for (int j = 0; j < (int)second.length(); j++) {
  42.         if (isalpha(second[j])) {  
  43.             temp2 = true;          
  44.         }
  45.         else
  46.         {
  47.             temp2 = false;
  48.             break;
  49.         }
  50.     }  
  51.  
  52.     if ((f == s) && (temp1 == true) && (temp2 == true))
  53.     {
  54.         cout << "Слова соответствуют условию" << endl;
  55.     }
  56.     else
  57.     {
  58.         cout << "Слова не соответствуют условию" << endl;
  59.     }
  60.  
  61.     if (!first.compare(second))
  62.     {
  63.         cout << "Строки равны" << endl;
  64.     }
  65.     else
  66.     {
  67.         cout << "Строки не равны" << endl;
  68.     }
  69.    
  70.    
  71.     for (int i = 0; i < first.length(); i++) {
  72.         string s;
  73.         s.assign(first);
  74.         s.erase(i, 1);
  75.         cout << "i = " << i << ", s = " << s << endl;
  76.         if (!second.compare(s)) {
  77.             cout << "Позиция " << i+1 << endl;
  78.         }
  79.     }
  80.    
  81.     system("pause");
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement