Advertisement
Milaj

Untitled

May 26th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <cctype>
  5. #include <Windows.h>
  6. using namespace std;
  7. void obnul(char*str) {
  8.     int sizee = sizeof(str) / sizeof(str[0]);
  9.     for (int i = 0; str[i] != sizee; i++)
  10.         str[i] = 0;
  11. }
  12. char a(char *text) {
  13.     int sizee = sizeof(text) / sizeof(text[0]);
  14.     char buff[255]; obnul(buff); short j = 0; int slovo=0;
  15.     for (int i=0; text[i] != sizee;++i) {
  16.         //Перебираем весь массив до конца
  17.         //Если не встретили пробел
  18.         // И Пристваиваем буферу первое слово
  19.         if (!isspace(text[i])||isalpha(text[i])) {
  20.             buff[j] = text[i];
  21.             j++;
  22.         }
  23.         //Если встретили пробел, а следующий элемент это не цифра или буква
  24.         //Начинаем сравнивать буфер со всеми словами до конца
  25.         else if (isspace(text[i])) {
  26.             short n = 0;//счетчик буфера
  27.             for (int k=0; text[k] != sizee; ++k) {
  28.                 //Если текущий элем буфера равен элему текста=> size++
  29.                 if (buff[n] == text[k]&&buff[n]!=sizee) {
  30.                     n++;
  31.                     continue;
  32.                 }
  33.                 //Если не равен и счетчик n=j => slovo++
  34.                 else if (buff[n] != text[k] && n == j) {
  35.                     slovo++;
  36.                     n = 0;
  37.                 }
  38.             }
  39.             cout << "Слов: " << buff << '=' << slovo << " штук"<<endl;
  40.             obnul(buff);
  41.             j = 0;
  42.             slovo = 0;
  43.         }
  44.     }
  45.     return 0;
  46. }
  47. int main()
  48. {
  49.     SetConsoleCP(1251);
  50.     SetConsoleOutputCP(1251);//Ввод и вывод на консоли сделать русским
  51.     char text[255]= ("There are two are two one this demo program ");
  52.     cout << "Исходный текст:\----------------------\n"<<text<<endl;
  53.     a(text);
  54.     system("pause");
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement