Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <locale.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- ////////////////
- struct WordC
- {
- int w;
- int ln;
- };
- /////////////////////////////////////////////
- int SearchWord(char *str, int *n)
- {
- int q= *n; char smb;
- while (str[q]!= NULL)
- {
- smb= str[q-1];
- if ( str[q]=='С' || str[q]=='с' && (isspace(smb) || ispunct(smb)) )
- { *n= q; return 1; }
- q++;
- }
- *n= q;
- return 0;
- }
- ///////////////////////////
- void EndWord(char *str, int *n)
- {
- int q= *n; char smb;
- while (str[q]!= NULL)
- {
- smb= str[q];
- if ( !isspace(smb) && !ispunct(smb) ) { q++; }
- else { *n=q; return; }
- }
- *n=q;
- return;
- }
- ////////////////////
- void OutWord(char *str, int fit, int lit)
- {
- while (fit<lit) { printf("%c", str[fit]); fit++; }
- }
- //////////////////////////////////////////////////
- int main()
- {
- system("chcp 1251 > nul");
- SetConsoleTitle("ОтветыМейлРу"); // Русские буквы
- //char s[255]="Самопроизвольно него и начнём...C++ В заданной Символьной!строке определить слово максимальной длины,(самостоятельно) начинающейся на букву 'с' ";
- char s[100]="Нет, простите, в тексте ничего по заданию...";
- printf("%s\n", s);
- struct WordC wc; wc.w= 0; wc.ln=0;
- int nn= 0; int Cfirst=0; int Csecond=0;
- if ( s[nn]=='С' || s[nn]=='с' )
- {
- Cfirst= nn; nn++;
- EndWord(s, &nn); Csecond= nn;
- if ( (Csecond-Cfirst)>(wc.ln-wc.w) ) { wc.w= Cfirst; wc.ln= Csecond; }
- }
- nn++;
- while (s[nn]!=NULL)
- {
- if ( !SearchWord(s, &nn) ) break;
- Cfirst= nn; nn++;
- EndWord(s, &nn); Csecond= nn;
- if ( (Csecond-Cfirst)>(wc.ln-wc.w) ) { wc.w= Cfirst; wc.ln= Csecond; }
- nn++;
- }
- if (wc.w==0 && wc.ln==0) { printf("Слов на букву 'c' или 'C' не найдено"); return 1; }
- printf("\nwc.w= %d \t wc.ln= %d\n", wc.w, wc.ln);
- OutWord(s, wc.w, wc.ln);
- printf("\n"); system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement