Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <cctype>
- #include <Windows.h>
- using namespace std;
- void obnul(char*str) {
- int sizee = sizeof(str) / sizeof(str[0]);
- for (int i = 0; str[i] != sizee; i++)
- str[i] = 0;
- }
- char a(char *text) {
- int sizee = sizeof(text) / sizeof(text[0]);
- char buff[255]; obnul(buff); short j = 0; int slovo=0;
- for (int i=0; text[i] != sizee;++i) {
- //Перебираем весь массив до конца
- //Если не встретили пробел
- // И Пристваиваем буферу первое слово
- if (!isspace(text[i])||isalpha(text[i])) {
- buff[j] = text[i];
- j++;
- }
- //Если встретили пробел, а следующий элемент это не цифра или буква
- //Начинаем сравнивать буфер со всеми словами до конца
- else if (isspace(text[i])) {
- short n = 0;//счетчик буфера
- for (int k=0; text[k] != sizee; ++k) {
- //Если текущий элем буфера равен элему текста=> size++
- if (buff[n] == text[k]&&buff[n]!=sizee) {
- n++;
- continue;
- }
- //Если не равен и счетчик n=j => slovo++
- else if (buff[n] != text[k] && n == j) {
- slovo++;
- n = 0;
- }
- }
- cout << "Слов: " << buff << '=' << slovo << " штук"<<endl;
- obnul(buff);
- j = 0;
- slovo = 0;
- }
- }
- return 0;
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);//Ввод и вывод на консоли сделать русским
- char text[255]= ("There are two are two one this demo program ");
- cout << "Исходный текст:\----------------------\n"<<text<<endl;
- a(text);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement