Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <malloc.h>
- #include <locale.h>
- //создаем динамическую строку любого размера
- char* createString() {
- char* string = (char*)malloc(sizeof(char));
- int length = 0;
- char symbol;
- symbol = getc(stdin);
- while (symbol != '\0' && symbol != '\n') {
- length++;
- realloc(string, length * sizeof(char));
- string[length - 1] = symbol;
- symbol = getc(stdin);
- }
- string[length] = '\0';
- return string;
- }
- //проверка на буквы
- bool isLetter(char symbol) {
- return ((symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z'));
- }
- //измеряем длинну слова
- int wordLength(char* string, int start) {
- int length = 0;
- while (isLetter(string[start + length]))
- length++;
- return length;
- }
- //идем к следующему слову
- int nextWordStart(char* string, int lastWordEnd) {
- lastWordEnd++;
- while (!isLetter(string[lastWordEnd]) && string[lastWordEnd] != '\0')
- lastWordEnd++;
- return lastWordEnd;
- }
- //проверка на последнее слово
- bool isLastWord(char* string, int start) {
- start += wordLength(string, start);
- if (string[start] == '\0')
- return true;
- else
- return false;
- }
- void main()
- {
- int K = 0;
- char newSymbol;
- scanf("%d %c \n", &K, &newSymbol);
- char* string = createString();
- int index = nextWordStart(string, wordLength(string, 0) - 1); //пропускаем первое слово
- while (!isLastWord(string, index)) {
- int currentWordLength = wordLength(string, index);
- if (currentWordLength > K) {
- index += K - 1;
- for (int i = K; i < currentWordLength; i++) {
- index++;
- string[index] = newSymbol;
- }
- }
- index = nextWordStart(string, index);
- }
- index = 0;
- while (string[index] != '\0') {
- printf("%c", string[index]);
- index++;
- }
- scanf("%d", &index);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement