Advertisement
AlejandroGY

Untitled

Sep 29th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. #include <string>
  4.  
  5. std::pair<bool, int> lang1(std::string& s, int i) {
  6.     int idx = i, last = i;
  7.     while (s[idx] == 'a' or s[idx] == 'b') {
  8.         if (s[idx] == 'a') last = idx;
  9.         idx++;
  10.     }
  11.     if (last != i) {
  12.         return { true, last + 1 };
  13.     } else {
  14.         return { false, i };
  15.     }
  16. }
  17.  
  18. std::pair<bool, int> lang2(std::string& s, int i) {
  19.     int idx = i, tam = s.size( );
  20.     while ((s[idx] == 'x' and s[idx + 1] == 'y') or (s[idx] == 'x' and s[idx + 1] == 'z')) {
  21.         idx += 2;
  22.     }
  23.     return { true, idx };
  24. }
  25.  
  26. std::pair<bool, int> lang3(std::string& s, int i) {
  27.     int idx = i;
  28.     while (std::isspace(s[idx])) idx++;
  29.     return { true, idx };
  30. }
  31.  
  32. int main( ) {
  33.     std::string cad;
  34.     std::getline(std::cin, cad, '!');
  35.     for (int i = 0; i < cad.size( ); ++i) {
  36.         if (cad[i] == 'a') {
  37.             std::pair<bool, int> res = lang1(cad, i);
  38.             if (res.first) {
  39.                 std::cout << "L1\n";
  40.                 i += (res.second - i - 1);
  41.             } else {
  42.                 std::cout << "ERROR\n";
  43.             }
  44.         } else if ((cad[i] == 'x' and cad[i + 1] == 'y') or (cad[i] == 'x' and cad[i + 1] == 'z')) {
  45.             std::pair<bool, int> res = lang2(cad, i);
  46.             if (res.first) {
  47.                 std::cout << "L2\n";
  48.                 i += (res.second - i - 1);
  49.             } else {
  50.                 std::cout << "ERROR\n";
  51.             }
  52.         } else if (std::isspace(cad[i])) {
  53.             std::pair<bool, int> res = lang3(cad, i);
  54.             if (res.first) {
  55.                 std::cout << "BLANK\n";
  56.                 i += (res.second - i - 1);
  57.             }
  58.         } else {
  59.             std::cout << "ERROR\n";
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement