Advertisement
pochti_da

Untitled

May 10th, 2021
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. enum {
  4.     READING_TEMPLATE,
  5.     READING_WORD,
  6.     READING_END,
  7.     READING_SPACES
  8. };
  9.  
  10. int main() {
  11.     int mode = READING_SPACES;
  12.     int k_cnt = 0, m_cnt = 0;
  13.     int curr_k_cnt = 0, curr_m_cnt = 0;
  14.  
  15.     int c;
  16.     while ((c = std::getchar()) != EOF) {
  17.         if (mode == READING_SPACES) {
  18.             if (c == '0') {
  19.                 mode = READING_TEMPLATE;
  20.  
  21.                 k_cnt = 1;
  22.                 m_cnt = 0;
  23.             } else if (!isspace(c)) {
  24.                 std::cout << 0 << '\n';
  25.                 mode = READING_END;
  26.             }
  27.         } else if (mode == READING_TEMPLATE) {
  28.             if (c == '0') {
  29.                 if (m_cnt != 0) {
  30.                     mode = READING_WORD;
  31.  
  32.                     curr_k_cnt = 1;
  33.                     curr_m_cnt = 0;
  34.                 }
  35.                 else {
  36.                     k_cnt += 1;
  37.                 }
  38.             } else if (c == '1') {
  39.                 m_cnt += 1;
  40.             } else if (isspace(c)) {
  41.                 std::cout << (m_cnt != 0) << '\n';
  42.                 mode = READING_SPACES;
  43.             } else {
  44.                 std::cout << 0 << '\n';
  45.                 mode = READING_END;
  46.             }
  47.         } else if (mode == READING_WORD) {
  48.             if (c == '0') {
  49.                 if (curr_k_cnt < k_cnt) {
  50.                     curr_k_cnt += 1;
  51.                 } else {
  52.                     std::cout << 0 << '\n';
  53.                     mode = READING_END;
  54.                 }
  55.             } else if (c == '1') {
  56.                 if (curr_k_cnt == k_cnt) {
  57.                     curr_m_cnt += 1;
  58.  
  59.                     if (curr_m_cnt == m_cnt) {
  60.                         curr_k_cnt = 0;
  61.                         curr_m_cnt = 0;
  62.                     }
  63.                 } else {
  64.                     std::cout << 0 << '\n';
  65.                     mode = READING_END;
  66.                 }
  67.             } else if (isspace(c)) {
  68.                 std::cout << (!curr_k_cnt && !curr_m_cnt) << '\n';
  69.                 mode = READING_SPACES;
  70.             } else {
  71.                 std::cout << 0 << '\n';
  72.                 mode = READING_END;
  73.             }
  74.         } else if (mode == READING_END) {
  75.             if (isspace(c)) {
  76.                 mode = READING_SPACES;
  77.             }
  78.         }
  79.     }
  80.  
  81.     if (mode == READING_WORD) {
  82.         std::cout << (!curr_k_cnt && !curr_m_cnt) << '\n';
  83.     } else if (mode == READING_TEMPLATE) {
  84.         std::cout << (m_cnt != 0) << '\n';
  85.     }
  86.  
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement