Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. //
  2. //#include "stdafx.h"
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cstdlib>
  6. #include <cstring>
  7. #include <clocale>
  8. #include <ctype.h>
  9. #include <conio.h>
  10.  
  11. #define MAX_SENTENCES 500
  12. #define MAX_WORDS 50
  13.  
  14. #define _CRT_SECURE_NO_WARNINGS
  15.  
  16. #pragma warning (disable : 4996)
  17.  
  18.  
  19. using namespace std;
  20.  
  21. class string_parser {
  22. public:
  23.     int get_sentences(char *p, int *sentence, int *coord);
  24. };
  25.  
  26. int main()
  27. {
  28.     setlocale(LC_ALL, "rus");
  29.  
  30.     string_parser sp;
  31.  
  32.     char str[1024];
  33.     char fname[128];
  34.     FILE *fp;
  35.  
  36.     printf("Имя файла: ");
  37.     scanf("%s", &fname[0]);
  38.     fp = fopen(fname, "r");
  39.  
  40.     if (fp == NULL) {
  41.         printf("Ошибка открытия файла\n");
  42.         return -1;
  43.     }
  44.  
  45.     char *p = &str[0];
  46.     memset(&str[0], '\0', sizeof(str));
  47.  
  48.     while (!feof(fp)) {
  49.         *p = fgetc(fp);
  50.         p++;
  51.     }
  52.  
  53.     *(p - 1) = ' ';
  54.  
  55.     int coord[MAX_SENTENCES][2];
  56.     int sentence = 0;
  57.  
  58.     memset(coord, -1, sizeof(coord));
  59.  
  60.     sp.get_sentences(&str[0], &sentence, &coord[0][0]);
  61.  
  62.     printf("Предложений: %d\n", sentence);
  63.  
  64.  
  65.     p = &str[0];
  66.     int pos = 0;
  67.     int curs = 0;
  68.  
  69.     int s[3] = { 1, 0, 2 };
  70.  
  71.     for (int i = 0;i <= sentence;i += 3) {
  72.         for (int j = 0;j<3;j++) {
  73.             if (i + s[j] >= sentence)
  74.                 break;
  75.             getch();
  76.             system("cls");
  77.             while (*p != '\0') {
  78.                 if (coord[i + s[j]][0] == pos)
  79.                     putchar('[');
  80.                 if (coord[i + s[j]][1] == pos - 1)
  81.                     putchar(']');
  82.                 putchar(*p);
  83.                 pos++;
  84.                 p++;
  85.             }
  86.             p = &str[0];
  87.             pos = 0;
  88.             curs++;
  89.         }
  90.     }
  91.  
  92.     printf("\n");
  93.     system("pause");
  94.  
  95.     return 0;
  96. }
  97.  
  98. int string_parser::get_sentences(char *p, int *sentence, int *coord)
  99. {
  100.     int pos, ld, inside;
  101.  
  102.     pos = ld = inside = 0;
  103.  
  104.     *sentence = 0;
  105.  
  106.     while (*p != '\0') {
  107.         if ((isalpha(*p) || isdigit(*p)) && !inside) {
  108.             *(coord + *sentence * 2 + 0) = pos;
  109.             inside = 1;
  110.             pos++;
  111.             p++;
  112.             continue;
  113.         }
  114.         if (*p == '.' || *p == '!' || *p == '?') {
  115.             if (pos - ld == 1) {
  116.                 ld = pos;
  117.                 pos++;
  118.                 p++;
  119.                 continue;
  120.             }
  121.             ld = pos;
  122.             *(coord + *sentence * 2 + 1) = pos;
  123.             (*sentence)++;
  124.             inside = 0;
  125.         }
  126.         p++;
  127.         pos++;
  128.     }
  129.  
  130.     return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement