Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- enum {
- READING_TEMPLATE,
- READING_WORD,
- READING_END,
- READING_SPACES
- };
- int main() {
- int mode = READING_SPACES;
- int k_cnt = 0, m_cnt = 0;
- int curr_k_cnt = 0, curr_m_cnt = 0;
- int c;
- while ((c = std::getchar()) != EOF) {
- if (mode == READING_SPACES) {
- if (c == '0') {
- mode = READING_TEMPLATE;
- k_cnt = 1;
- m_cnt = 0;
- } else if (!isspace(c)) {
- std::cout << 0 << '\n';
- mode = READING_END;
- }
- } else if (mode == READING_TEMPLATE) {
- if (c == '0') {
- if (m_cnt != 0) {
- mode = READING_WORD;
- curr_k_cnt = 1;
- curr_m_cnt = 0;
- }
- else {
- k_cnt += 1;
- }
- } else if (c == '1') {
- m_cnt += 1;
- } else if (isspace(c)) {
- std::cout << (m_cnt != 0) << '\n';
- mode = READING_SPACES;
- } else {
- std::cout << 0 << '\n';
- mode = READING_END;
- }
- } else if (mode == READING_WORD) {
- if (c == '0') {
- if (curr_k_cnt < k_cnt) {
- curr_k_cnt += 1;
- } else {
- std::cout << 0 << '\n';
- mode = READING_END;
- }
- } else if (c == '1') {
- if (curr_k_cnt == k_cnt) {
- curr_m_cnt += 1;
- if (curr_m_cnt == m_cnt) {
- curr_k_cnt = 0;
- curr_m_cnt = 0;
- }
- } else {
- std::cout << 0 << '\n';
- mode = READING_END;
- }
- } else if (isspace(c)) {
- std::cout << (!curr_k_cnt && !curr_m_cnt) << '\n';
- mode = READING_SPACES;
- } else {
- std::cout << 0 << '\n';
- mode = READING_END;
- }
- } else if (mode == READING_END) {
- if (isspace(c)) {
- mode = READING_SPACES;
- }
- }
- }
- if (mode == READING_WORD) {
- std::cout << (!curr_k_cnt && !curr_m_cnt) << '\n';
- } else if (mode == READING_TEMPLATE) {
- std::cout << (m_cnt != 0) << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement