Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. // lab33.cpp
  2. //
  3.  
  4.     #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     char str1[80], str2[80], str3[160];
  9.     int i, j, count;
  10.  
  11. /*Ввод строк*/
  12.     printf("Enter first string:\t");
  13.     gets_s(str1);
  14.  
  15.     printf("Enter second string:\t");
  16.     gets_s(str2);
  17.  
  18. /*Подсчет длины*/
  19.     i = 0;
  20.     do
  21.     {
  22.         str1[i] != '\0'; i++;
  23.     }
  24.     while(str1[i] != '\0');
  25.    
  26.     printf("First string length is:\t%d chars\n",i);
  27.  
  28.     j=0;
  29.     do
  30.     {
  31.         str2[j] != '\0'; j++;
  32.     }
  33.     while(str2[j]!='\0');
  34.     printf("Second string length is:\t%d chars\n",j);
  35.  
  36. /*Соединение строк*/
  37.     for(i=0,j=0;str1[i] != '\0';i++)
  38.     {
  39.         if(str1[i]!=' ')
  40.         {
  41.             str3[j]=str1[i];
  42.             j++;
  43.         }
  44.     }
  45.    
  46.     for(i=0;str2[i] != '\0';i++)
  47.     {
  48.         if(str2[i]!=' ')
  49.         {
  50.             str3[j]=str2[i];
  51.             j++;
  52.         }
  53.     }
  54.     str3[j] = '\0';
  55.    
  56.     printf("First string plus second string are:\t");
  57.     puts(str3);
  58.  
  59. /*Замена символов, совпадающих с последним символом в строке, на пробел*/
  60.     for(i=0, count=0; i<j-1;i++)
  61.     {
  62.           if(str3[i]==str3[i+1]){str3[i]=' ';str3[i+1]=' ';count++;}
  63.             if(count>=4) break;
  64.    
  65.     }
  66.    
  67.     printf("Modified string is:\t");
  68.     puts(str3);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement