Advertisement
Guest User

Untitled

a guest
Jun 18th, 2021
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include <windows.h>
  2. #include <locale.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8.  
  9. ////////////////
  10.  
  11. struct WordC
  12. {
  13. int w;
  14. int ln;
  15. };
  16.  
  17. /////////////////////////////////////////////
  18.  
  19. int SearchWord(char *str, int *n)
  20. {
  21. int q= *n; char smb;
  22. while (str[q]!= NULL)
  23. {
  24. smb= str[q-1];
  25. if ( str[q]=='С' || str[q]=='с' && (isspace(smb) || ispunct(smb)) )
  26. { *n= q; return 1; }
  27. q++;
  28. }
  29. *n= q;
  30. return 0;
  31. }
  32.  
  33. ///////////////////////////
  34.  
  35. void EndWord(char *str, int *n)
  36. {
  37. int q= *n; char smb;
  38. while (str[q]!= NULL)
  39. {
  40. smb= str[q];
  41. if ( !isspace(smb) && !ispunct(smb) ) { q++; }
  42. else { *n=q; return; }
  43. }
  44. *n=q;
  45. return;
  46. }
  47.  
  48. ////////////////////
  49.  
  50. void OutWord(char *str, int fit, int lit)
  51. {
  52. while (fit<lit) { printf("%c", str[fit]); fit++; }
  53. }
  54.  
  55. //////////////////////////////////////////////////
  56.  
  57. int main()
  58. {
  59. system("chcp 1251 > nul");
  60. SetConsoleTitle("ОтветыМейлРу"); // Русские буквы
  61.  
  62. //char s[255]="Самопроизвольно него и начнём...C++ В заданной Символьной!строке определить слово максимальной длины,(самостоятельно) начинающейся на букву 'с' ";
  63. char s[100]="Нет, простите, в тексте ничего по заданию...";
  64.  
  65. printf("%s\n", s);
  66. struct WordC wc; wc.w= 0; wc.ln=0;
  67.  
  68. int nn= 0; int Cfirst=0; int Csecond=0;
  69.  
  70. if ( s[nn]=='С' || s[nn]=='с' )
  71. {
  72. Cfirst= nn; nn++;
  73. EndWord(s, &nn); Csecond= nn;
  74. if ( (Csecond-Cfirst)>(wc.ln-wc.w) ) { wc.w= Cfirst; wc.ln= Csecond; }
  75. }
  76.  
  77. nn++;
  78.  
  79. while (s[nn]!=NULL)
  80. {
  81. if ( !SearchWord(s, &nn) ) break;
  82.  
  83. Cfirst= nn; nn++;
  84.  
  85. EndWord(s, &nn); Csecond= nn;
  86.  
  87. if ( (Csecond-Cfirst)>(wc.ln-wc.w) ) { wc.w= Cfirst; wc.ln= Csecond; }
  88.  
  89. nn++;
  90. }
  91.  
  92. if (wc.w==0 && wc.ln==0) { printf("Слов на букву 'c' или 'C' не найдено"); return 1; }
  93.  
  94. printf("\nwc.w= %d \t wc.ln= %d\n", wc.w, wc.ln);
  95. OutWord(s, wc.w, wc.ln);
  96.  
  97. printf("\n"); system("pause");
  98. return 0;
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement