Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <utility>
- #include <string>
- std::pair<bool, int> lang1(std::string& s, int i) {
- int idx = i, last = i;
- while (s[idx] == 'a' or s[idx] == 'b') {
- if (s[idx] == 'a') last = idx;
- idx++;
- }
- if (last != i) {
- return { true, last + 1 };
- } else {
- return { false, i };
- }
- }
- std::pair<bool, int> lang2(std::string& s, int i) {
- int idx = i, tam = s.size( );
- while ((s[idx] == 'x' and s[idx + 1] == 'y') or (s[idx] == 'x' and s[idx + 1] == 'z')) {
- idx += 2;
- }
- return { true, idx };
- }
- std::pair<bool, int> lang3(std::string& s, int i) {
- int idx = i;
- while (std::isspace(s[idx])) idx++;
- return { true, idx };
- }
- int main( ) {
- std::string cad;
- std::getline(std::cin, cad, '!');
- for (int i = 0; i < cad.size( ); ++i) {
- if (cad[i] == 'a') {
- std::pair<bool, int> res = lang1(cad, i);
- if (res.first) {
- std::cout << "L1\n";
- i += (res.second - i - 1);
- } else {
- std::cout << "ERROR\n";
- }
- } else if ((cad[i] == 'x' and cad[i + 1] == 'y') or (cad[i] == 'x' and cad[i + 1] == 'z')) {
- std::pair<bool, int> res = lang2(cad, i);
- if (res.first) {
- std::cout << "L2\n";
- i += (res.second - i - 1);
- } else {
- std::cout << "ERROR\n";
- }
- } else if (std::isspace(cad[i])) {
- std::pair<bool, int> res = lang3(cad, i);
- if (res.first) {
- std::cout << "BLANK\n";
- i += (res.second - i - 1);
- }
- } else {
- std::cout << "ERROR\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement