Advertisement
evage

В-3 зд - 1. Предложение-перевёртыш

Sep 19th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4. const int LEN = 1000;
  5. unsigned char rus(unsigned char a) {
  6.     if (a >= 192 && a <= 223)
  7.         return a + 32;
  8.     return a;
  9. }
  10. void my_gets(unsigned char* ar, int l) {
  11.     int i = 0;
  12.     unsigned char a = getchar();
  13.     while (a != '\n' && a != '.' && i < l && a != '!') {
  14.         if (a != ' ' && a != ',' && a != '-' && a != '—') {
  15.             ar[i] = rus(a);
  16.             ++i;
  17.         }
  18.         a = getchar();
  19.     }
  20.     ar[i] = '\0';
  21. }
  22. void string_reverse(unsigned char* source, unsigned char * dest, int l){
  23.     for (int i = 0; i < l; ++i)
  24.         dest[i] = source[l - i - 1];
  25.     dest[l] = '\0';
  26. }
  27. int check(unsigned char* source, unsigned char* rcopy, int l) {
  28.     int flag = 1;
  29.     for (int i = 0; i < l; ++i) {
  30.         if (source[i] != rcopy[i]) {
  31.             flag = 0;
  32.             break;
  33.         }
  34.     }
  35.     return flag;
  36. }
  37. int my_len(unsigned char* source) {
  38.     int i = 0;
  39.     while (source[i++] != '\0')
  40.         ;
  41.     return --i;
  42. }
  43. int main() {
  44.     SetConsoleOutputCP(1251);    //#include <windows.h>
  45.     SetConsoleCP(1251);
  46.     unsigned char source[LEN];
  47.     unsigned char rcopy[LEN];
  48.    
  49.     my_gets(source, LEN);
  50.     int len = my_len(source);
  51.     string_reverse(source, rcopy, len);
  52.    
  53.     if (check(source, rcopy, len))
  54.         cout << "Перевёртыш";
  55.     else
  56.         cout << "Не перевёртыш";
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement