Advertisement
35657

Untitled

Apr 20th, 2024
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.    
  9.     SetConsoleCP(1251);
  10.     SetConsoleOutputCP(1251);
  11.    
  12.     char line[100];
  13.  
  14.     cout << "Введите строку: ";
  15.     gets_s(line);
  16.  
  17.     char ch;
  18.  
  19.     cout << "Введите символ: ";
  20.     cin >> ch;
  21.    
  22.     for (int i = strlen(line) - 1; i >= 0; i--) {
  23.         if (line[i] == ch) {
  24.             cout << i + 1 << " ";
  25.             return 0;
  26.         }
  27.     }
  28.     cout << "Нет такого символа" << endl;
  29.    
  30.     // второй вариант
  31.     /*int i = strlen(line) - 1;
  32.  
  33.     for (; i >= 0; i--) {
  34.         if (line[i] == ch) {
  35.             cout << i + 1 << " ";
  36.             break;
  37.         }
  38.     }
  39.     if (i == -1) {
  40.         cout << "Нет такого символа" << endl;
  41.     }*/
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement