#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<fstream>
#include<cstddef>
using namespace std;
int main()
{
ifstream fin;
fin.open("CYK.txt");
vector<string> pr;
string s,str="";
while(!fin.eof())
{
getline(fin,s);
cout<<s<<endl;
pr.push_back(s);
}
int nor = pr.size();
for(int i=0; i<nor;i++)
{
if(pr[i][0]=='S')
{
str = pr[i];
break;
}
}
if(str =="")
{
cout<<" Invalid Grammar";
return 0;
}
char rs[nor];
for(int i=0; i<nor;i++)
rs[i]= pr[i][0];
string temp;
vector<string> ls[nor];
size_t f;
for(int i=0; i<nor;i++)
{
f = pr[i].find_first_of('|');
temp = pr[i].substr(3,f-3);
while(f!=std::string::npos)
{
int t=f+1;
f=pr[i].find('|',f+1);
temp = pr[i].substr(t,f-t);
ls[i].push_back(temp);
}
}
string ip;
cout<<"Enter String = ";
cin>>ip;
string tempo="";
int len = ip.length();
vector <string> TT[len];
for(int i=0; i<len; i++)
{
temp ="";
temp = temp + ip[i];
for(int k=0; k<nor;k++)
{
for(int j=0; j<ls[k].size();j++)
{
if(ls[k][j].compare(temp)==0)
TT[0][i]=TT[0][i]+rs[k];
}
}
}
cout<<TT[0];
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0ZGlvLmg+CiNpbmNsdWRlPHN0cmluZy5oPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPGZzdHJlYW0+CiNpbmNsdWRlPGNzdGRkZWY+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICAgICAgaWZzdHJlYW0gZmluOwogICAgICBmaW4ub3BlbigiQ1lLLnR4dCIpOwogICAgICB2ZWN0b3I8c3RyaW5nPiBwcjsKICAgICAgc3RyaW5nIHMsc3RyPSIiOwogICAgICAKICAgICAgd2hpbGUoIWZpbi5lb2YoKSkKICAgICAgewogICAgICAgZ2V0bGluZShmaW4scyk7CiAgICAgICBjb3V0PDxzPDxlbmRsOwogICAgICAgcHIucHVzaF9iYWNrKHMpOyAgICAgICAgICAgICAgICAgCiAgICAgIH0KICAgICAgCgkgIGludCBub3IgPSBwci5zaXplKCk7CiAgICAgIGZvcihpbnQgaT0wOyBpPG5vcjtpKyspCiAgICAgIHsKICAgICAgICAgICAgICBpZihwcltpXVswXT09J1MnKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0ciA9IHByW2ldOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICB9CiAgICAgCiAgICAgICBpZihzdHIgPT0iIikgCiAgICAgICB7IAogICAgICAgICAgICAgIGNvdXQ8PCIgSW52YWxpZCBHcmFtbWFyIjsKICAgICAgICAgICAgICByZXR1cm4gMDsKICAgICAgIH0KICAgICAgCiAgICAgICBjaGFyIHJzW25vcl07CiAgICAgICBmb3IoaW50IGk9MDsgaTxub3I7aSsrKQogICAgICAgcnNbaV09IHByW2ldWzBdOwogICAKICAgICAgIHN0cmluZyB0ZW1wOwogICAgICAgdmVjdG9yPHN0cmluZz4gbHNbbm9yXTsKICAgICAgIAogICAgICAgc2l6ZV90IGY7CiAgICAgIGZvcihpbnQgaT0wOyBpPG5vcjtpKyspCiAgICAgIHsKICAgICAgICBmID0gcHJbaV0uZmluZF9maXJzdF9vZignfCcpOwogICAgICAgIHRlbXAgPSBwcltpXS5zdWJzdHIoMyxmLTMpOwogICAgICAgIHdoaWxlKGYhPXN0ZDo6c3RyaW5nOjpucG9zKQogICAgICAgIHsKICAgICAgICAJaW50IHQ9ZisxOwoJCQlmPXByW2ldLmZpbmQoJ3wnLGYrMSk7CiAgICAgICAgCXRlbXAgPSBwcltpXS5zdWJzdHIodCxmLXQpOwogICAgICAgIAlsc1tpXS5wdXNoX2JhY2sodGVtcCk7CiAgICAgICAgfQogICAgIH0KCQkKCSAKICAgICAgc3RyaW5nIGlwOwogICAgICBjb3V0PDwiRW50ZXIgU3RyaW5nID0gIjsKICAgICAgY2luPj5pcDsKICAgICAgc3RyaW5nIHRlbXBvPSIiOwogICAgICBpbnQgbGVuID0gaXAubGVuZ3RoKCk7CiAgICAgIHZlY3RvciA8c3RyaW5nPiBUVFtsZW5dOwogICAgICBmb3IoaW50IGk9MDsgaTxsZW47IGkrKykKICAgICAgeyAgICAKCSAgICAgIHRlbXAgPSIiOyAgICAKICAgICAgICAgICAgICB0ZW1wID0gdGVtcCArIGlwW2ldOwogICAgICAgICAgICAgIGZvcihpbnQgaz0wOyBrPG5vcjtrKyspCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBmb3IoaW50IGo9MDsgajxsc1trXS5zaXplKCk7aisrKQogICAgICAgICAgICAgICAgeyAgICAgIAoJCQkJICBpZihsc1trXVtqXS5jb21wYXJlKHRlbXApPT0wKQogICAgICAgICAgICAgICAgICBUVFswXVtpXT1UVFswXVtpXStyc1trXTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICB9CiAgICAgICAgICAgCiBjb3V0PDxUVFswXTsKICAgcmV0dXJuIDA7ICAKfSA=
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)
^