LB 8
unknown
c_cpp
2 years ago
1.1 kB
6
Indexable
#include <iostream> #include <string.h> #include <cstdio> using namespace std; int main() { const int MAX_INPUT_SIZE = 1000; char input[MAX_INPUT_SIZE]; cout << "Enter a sentence: "; cin.getline(input, MAX_INPUT_SIZE); char* words[MAX_INPUT_SIZE]; int wordCount = 0; int middleWordIndex = -1; //Токенізація вхідних даних та підрахунок слів char* token = strtok(input, " "); while (token != nullptr) { words[wordCount++] = token; token = strtok(nullptr, " "); } if (wordCount > 0) { middleWordIndex = wordCount / 2; } // Вивести речення з виділеним середнім словом cout << "Highlighted sentence: "; for (int i = 0; i < wordCount; ++i) { if (i == middleWordIndex) { cout << "*" << words[i] << "*"; // Виділення тексту } else { cout << words[i]; } cout << ' '; } cout << endl; return 0; }
Editor is loading...