fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <set>
  4. #include <map>
  5. using namespace std;
  6.  
  7. typedef int state;
  8. typedef pair<state,char> keypair;
  9. typedef map<keypair,state> statemap;
  10. typedef pair<statemap,set<state> > automat;
  11.  
  12. int main()
  13. {
  14. const automat a // c++ 11 dla tej inicjalizacji
  15. {
  16. {
  17. {{0,'a'},1},
  18. {{1,'b'},1},
  19. {{1,'c'},2},
  20. {{0,'k'},3},
  21. {{3,'o'},4},
  22. {{4,'t'},5},
  23. },
  24. {2,5}
  25. };
  26. for(string str;(cin>>str)&&(str.size());)
  27. {
  28. state st=0;
  29. for(string::iterator ch=str.begin();(ch!=str.end())&&(st>=0);++ch)
  30. {
  31. statemap::const_iterator fnd=a.first.find(keypair(st,*ch));
  32. if(fnd!=a.first.end()) st=fnd->second; else st=-1;
  33. }
  34. cout<<(a.second.find(st)!=a.second.end()?"TAK":"NIE")<<endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 3480KB
stdin
x
kot
ac
abc
abbc
abbbbbbc
akot
stdout
NIE
TAK
TAK
TAK
TAK
TAK
NIE