fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct ss {string s;char typ;};
  7.  
  8. int main()
  9. {
  10. vector<ss> res;
  11. string s;
  12. string w;
  13. bool isW;
  14. bool com;
  15. int nw,pos,l,posw,wc;
  16. ss pst;
  17.  
  18. //cin >> s;
  19. getline(cin,s);
  20.  
  21. l = s.length();
  22. isW=false;
  23. com=false;
  24. string d="";
  25. for(int i=0;i<l;i++)
  26. {
  27. if(!isW && ((s[i]>='A' && s[i]<='Z') || (s[i]>='a' && s[i]<='z')))
  28. {
  29. w=s[i];
  30. isW = true;
  31. if(d.length()>0)
  32. {
  33. pst.s = d;
  34. if (com)
  35. pst.typ=2;
  36. else
  37. pst.typ=1;
  38. res.push_back(pst);
  39. }
  40. com=false;
  41. }
  42. else if (isW && ((s[i]>='A' && s[i]<='Z') || (s[i]>='a' && s[i]<='z')))
  43. {
  44. w+=s[i];
  45. }
  46. else if (isW && !((s[i]>='A' && s[i]<='Z') || (s[i]>='a' && s[i]<='z')))
  47. {
  48. if(w.length()>0)
  49. {
  50. pst.s = w;
  51. if (w == "and" || w == "or" || w == "OR" || w == "oR" || w == "Or" || w == "And" || w == "ANd" || w == "AND" || w == "AnD" || w == "aNd" || w == "aND" || w == "anD")
  52. pst.typ = 4;
  53. else
  54. pst.typ=3;
  55. res.push_back(pst);
  56. }
  57. isW=false;
  58. d = s[i];
  59. if (s[i] == ',')
  60. com=true;
  61. }
  62. else
  63. {
  64. d+=s[i];
  65. if(s[i] == ',')
  66. com=true;
  67. }
  68. }
  69. l=res.size();
  70. wc=0;
  71. com=false;
  72. for(int i=0;i<l;i++)
  73. {
  74. if(!wc)
  75. {
  76. if(res[i].typ == 2 && !wc && i)
  77. {
  78. wc = 1;
  79. }
  80. cout << res[i].s;
  81. }
  82. else
  83. {
  84. if (!com)
  85. {
  86. if(res[i].typ == 2 || res[i].typ == 4)
  87. cout << res[i].s;
  88. else if(res[i].typ == 3)
  89. {
  90. cout << res[i].s;
  91. wc++;
  92. }
  93. else
  94. com = true;
  95. }
  96. else
  97. {
  98. if(res[i].typ == 3)
  99. {
  100. cout << res[i-1].s << res[i].s;
  101. }
  102. else if (res[i].typ == 4)
  103. {
  104. if(wc >=2)
  105. cout << ',' << res[i-1].s << res[i].s;
  106. else
  107. cout << res[i-1].s << res[i].s;
  108. }
  109. wc=0;
  110. com=false;
  111. }
  112. }
  113. }
  114. cout << '.';
  115. return 0;
  116. }
Success #stdin #stdout 0s 4552KB
stdin
He knows C, Python, Perl, or Ruby.
stdout
He knows C, Python, Perl, or Ruby.