Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. // void dfa(vector<int> alphabet, int row, int col, int mat[][], int fs, string input){
  7. // int state_row;
  8. // for(int i=0; i<input.size(); i++){
  9. // cout << "Input alphabet : "<<input[i]<<endl;
  10. // for(int j=0; j<col; j++){
  11. // if(input[i] == alphabet[j]){
  12. // for(int k=0; k<row; k++){
  13. // state_row = mat[k][j];
  14. // cout << "Current State : "<<state_row<<endl;
  15. // if(state_row == fs){
  16. // cout << "State is accepted\n";
  17. // }else{
  18. // cout << "State is not accepted\n";
  19. // }
  20. // }
  21. // }
  22. // }
  23. // }
  24. // }
  25. int main(){
  26. int r = 5;
  27. int c = 3;
  28.  
  29. cout << "Enter alphabet :\n";
  30. int alphabet[c];
  31. for(int i=0; i<c; i++){
  32. cin>> alphabet[i];
  33. }
  34.  
  35. cout << endl;/////////////////////////////////
  36. cout << "Input the matrix values ( < rows): \n";
  37.  
  38. int matrix[r][c];
  39. for(int i=0; i<r; i++){
  40. for(int j=0; j<c; j++){
  41. cin>>matrix[i][j];
  42. }
  43. }
  44. cout << endl;////////////////////////////////
  45. cout << "Enter Final State ( < rows): \n";
  46. int final_state;
  47. cin>> final_state;
  48. cout << endl;////////////////////////////////
  49. cout <<"Enter input string :\n";
  50. string input;
  51. cin>>input;
  52.  
  53. // dfa(alphabet, r, c, matrix, final_state, input);
  54.  
  55. int state_row = 0;
  56. cout << "Start State : "<<state_row<<endl;
  57. for(int i=0; i<input.size(); i++){
  58. cout << "Input alphabet : "<<input[i]<<endl;
  59. state_row=matrix[state_row][input[i]-'0'];
  60. // cout << "asdklfjsadf :" << input[i]-'0'<<endl;
  61. cout << "Current State : "<<state_row<<endl;
  62. if(state_row==final_state){
  63. cout << "State is accepted\n";
  64. }else{
  65. cout << "State is not accepted\n";
  66. }
  67.  
  68. cout << endl;
  69. }
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement