Untitled
unknown
plain_text
2 years ago
1.0 kB
1
Indexable
Never
#include <iostream> #include <string> using namespace std; int main() { string input; cout << "Enter a string: "; getline(cin, input); bool match1 = true; for (char c : input) { if (c != 'a' && c != 'b' && c != 'c') { match1 = false; break; } } if (match1) { cout << "String \"" << input << "\" matches the regular expression a+b+c*" << endl; } else { cout << "String \"" << input << "\" does not match the regular expression a+b+c*" << endl; } bool match2 = true; for (int i = 0; i < input.length(); i++) { if (input[i] == 'a' && (i == input.length() - 1 || input[i+1] != 'b')) { match2 = false; break; } } if (match2) { cout << "String \"" << input << "\" matches the regular expression ab*" << endl; } else { cout << "String \"" << input << "\" does not match the regular expression ab*" << endl; } return 0; }