Advertisement
hurmawe

5day

Apr 15th, 2022
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <cstdio>
  6.  
  7.  
  8.  
  9. int main()
  10. {
  11.     SetConsoleCP(1251);
  12.     SetConsoleOutputCP(1251);
  13.     setlocale(LC_ALL, "Russsian");
  14.  
  15.     int qunter = 0;
  16.     char str[80];
  17.     printf("Введите предложение:\n");
  18.     std::cin.getline(str, 80);
  19.  
  20.  
  21.     ////////////////////////////////////////////////
  22.     //Задание 1/////////////////////////////////////
  23.     ////////////////////////////////////////////////
  24.  
  25.     for (int i = 0; i < 80; i++)
  26.     {
  27.         if ((str[i+1] == '\0' or str[i + 1] == ' ') and str[i] == 'а')
  28.         {
  29.             qunter++;
  30.         }
  31.     }
  32.     if (!qunter)
  33.     {
  34.         printf("Нет таких слов\n");
  35.     }
  36.     else
  37.     {
  38.         printf("Найдено слов %d\n", qunter);
  39.     }
  40.    
  41.    ////////////////////////////////////////////////
  42.    //Задание 2/////////////////////////////////////
  43.    ////////////////////////////////////////////////
  44.  
  45.  
  46.     char buff[80];
  47.     printf("Введите предложение:\n");
  48.     std::cin.getline(str, 80);
  49.     qunter = 0;
  50.  
  51.     for (int i = 0, j=0; i < 80; i++)
  52.     {
  53.         if (str[i] == '\0' or str[i] == ' ')
  54.         {
  55.             if (qunter == 0)
  56.             {
  57.                 printf("Результат:\n");
  58.                 qunter = 1;
  59.             }
  60.             for (int k = 0; k < j; k++)
  61.             {
  62.                 printf("%c",buff[k]);
  63.             }
  64.             printf("\n");
  65.             j = 0;
  66.         }
  67.         else
  68.         {
  69.             buff[j] = str[i];
  70.             j++;
  71.         }
  72.     }
  73.     if (qunter == 0)
  74.     {
  75.         printf("Вы не ввели слов");
  76.     }
  77.  
  78. }
  79.  
  80.  
  81. int main()
  82. {
  83.     ////////////////////////////////////////////////
  84.     //Задание 3/////////////////////////////////////
  85.     ////////////////////////////////////////////////
  86.  
  87.     char str[80];
  88.     char buff[80];
  89.     char buff1[80];
  90.     char buff2[80];
  91.     printf("Введите имя файла\n");
  92.     gets(str);
  93.     int len = strlen(str);
  94.     if (len == 0)
  95.     {
  96.         printf("Некоретный ввод\n");
  97.     }
  98.     else
  99.     {
  100.     for (int i = len - 1; i >= 0; i--)
  101.     {
  102.        
  103.         if (str[i] == '.')
  104.         {
  105.             strcpy(str+i+1, "exe\n");
  106.             break;
  107.         }
  108.         if (str[i] == '\\' && len!=1)
  109.         {
  110.             strcat(str, ".exe\n");
  111.             break;
  112.         }
  113.         if(i==0 && str[i] != '\\')
  114.         {
  115.         strcat(str, ".exe\n");
  116.         }  
  117.     }
  118.     puts(str);
  119. }
  120.    
  121.     ////////////////////////////////////////////////
  122.      //Задание 4/////////////////////////////////////
  123.      ////////////////////////////////////////////////
  124.     printf("Введите ФИО\n");
  125.     gets(str);
  126.     len=strlen(str);
  127.     int qunter=0;
  128.     for(int i=0,j=0;i<len;i++)
  129.     {
  130.         if (str[i] == ' ')
  131.         {
  132.             if(qunter==0)
  133.             {
  134.             strcpy(buff1,buff);
  135.             j = 0;
  136.             qunter++;
  137.             } else if(qunter==1)
  138.             {
  139.             strcpy(buff2,buff);
  140.             j=0;
  141.             qunter++;
  142.             }
  143.         }
  144.          else
  145.         {
  146.             buff[j] = str[i];
  147.             j++;
  148.         }
  149.     }
  150.     printf("Привет, %s %s\n",buff2,buff1);
  151.    
  152.  
  153. }
  154.  
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement