Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- using namespace std;
- // void dfa(vector<int> alphabet, int row, int col, int mat[][], int fs, string input){
- // int state_row;
- // for(int i=0; i<input.size(); i++){
- // cout << "Input alphabet : "<<input[i]<<endl;
- // for(int j=0; j<col; j++){
- // if(input[i] == alphabet[j]){
- // for(int k=0; k<row; k++){
- // state_row = mat[k][j];
- // cout << "Current State : "<<state_row<<endl;
- // if(state_row == fs){
- // cout << "State is accepted\n";
- // }else{
- // cout << "State is not accepted\n";
- // }
- // }
- // }
- // }
- // }
- // }
- int main(){
- int r = 5;
- int c = 3;
- cout << "Enter alphabet :\n";
- int alphabet[c];
- for(int i=0; i<c; i++){
- cin>> alphabet[i];
- }
- cout << endl;/////////////////////////////////
- cout << "Input the matrix values ( < rows): \n";
- int matrix[r][c];
- for(int i=0; i<r; i++){
- for(int j=0; j<c; j++){
- cin>>matrix[i][j];
- }
- }
- cout << endl;////////////////////////////////
- cout << "Enter Final State ( < rows): \n";
- int final_state;
- cin>> final_state;
- cout << endl;////////////////////////////////
- cout <<"Enter input string :\n";
- string input;
- cin>>input;
- // dfa(alphabet, r, c, matrix, final_state, input);
- int state_row = 0;
- cout << "Start State : "<<state_row<<endl;
- for(int i=0; i<input.size(); i++){
- cout << "Input alphabet : "<<input[i]<<endl;
- state_row=matrix[state_row][input[i]-'0'];
- // cout << "asdklfjsadf :" << input[i]-'0'<<endl;
- cout << "Current State : "<<state_row<<endl;
- if(state_row==final_state){
- cout << "State is accepted\n";
- }else{
- cout << "State is not accepted\n";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement