fork download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<vector>
  5. #include<fstream>
  6. #include<cstddef>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. ifstream fin;
  12. fin.open("CYK.txt");
  13. vector<string> pr;
  14. string s,str="";
  15.  
  16. while(!fin.eof())
  17. {
  18. getline(fin,s);
  19. cout<<s<<endl;
  20. pr.push_back(s);
  21. }
  22.  
  23. int nor = pr.size();
  24. for(int i=0; i<nor;i++)
  25. {
  26. if(pr[i][0]=='S')
  27. {
  28. str = pr[i];
  29. break;
  30. }
  31. }
  32.  
  33. if(str =="")
  34. {
  35. cout<<" Invalid Grammar";
  36. return 0;
  37. }
  38.  
  39. char rs[nor];
  40. for(int i=0; i<nor;i++)
  41. rs[i]= pr[i][0];
  42.  
  43. string temp;
  44. vector<string> ls[nor];
  45.  
  46. size_t f;
  47. for(int i=0; i<nor;i++)
  48. {
  49. f = pr[i].find_first_of('|');
  50. temp = pr[i].substr(3,f-3);
  51. while(f!=std::string::npos)
  52. {
  53. int t=f+1;
  54. f=pr[i].find('|',f+1);
  55. temp = pr[i].substr(t,f-t);
  56. ls[i].push_back(temp);
  57. }
  58. }
  59.  
  60.  
  61. string ip;
  62. cout<<"Enter String = ";
  63. cin>>ip;
  64. string tempo="";
  65. int len = ip.length();
  66. vector <string> TT[len];
  67. for(int i=0; i<len; i++)
  68. {
  69. temp ="";
  70. temp = temp + ip[i];
  71. for(int k=0; k<nor;k++)
  72. {
  73.  
  74. for(int j=0; j<ls[k].size();j++)
  75. {
  76. if(ls[k][j].compare(temp)==0)
  77. TT[0][i]=TT[0][i]+rs[k];
  78. }
  79. }
  80. }
  81.  
  82. cout<<TT[0];
  83. return 0;
  84. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:74:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int j=0; j<ls[k].size();j++)
                                           ^
prog.cpp:82:12: error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’
  cout<<TT[0];
            ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:602:5: error:   initializing argument 1 of ‘std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::vector<std::basic_string<char> >]’
     operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
     ^
stdout
Standard output is empty