fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. vector<string> Explode_L(const string &str, const string &d){
  5. int s = 0;
  6. int i = 0;
  7. int j;
  8. vector<string> res;
  9. while(i + d.size() - 1 < str.size()){
  10. for(j=(0);j<(d.size());j++){
  11. if(str[i+j] != d[j]){
  12. break;
  13. }
  14. }
  15. if(j != d.size()){
  16. i++;
  17. continue;
  18. }
  19. res.push_back(str.substr(s, i-s));
  20. s = (i += d.size());
  21. }
  22. res.push_back(str.substr(s));
  23. return res;
  24. }
  25. string Implode_L(const vector<string> &v, const string &d){
  26. int i;
  27. string res;
  28. if(v.size()==0){
  29. return res;
  30. }
  31. res += v[0];
  32. for(i=(1);i<(v.size());i++){
  33. res += d;
  34. res += v[i];
  35. }
  36. return res;
  37. }
  38. #define main dummy_main
  39. int main(){
  40. return 0;
  41. }
  42. #undef main
  43. map<string, int> mp;
  44. string lis[10][20];
  45. int tot;
  46. int sz[10];
  47. vector<string> res;
  48. vector<string> in;
  49. vector<string> tmp;
  50. void solve(int dep){
  51. int i;
  52. int k;
  53. if(dep==in.size()){
  54. res.push_back(Implode_L(tmp, " "));
  55. return;
  56. }
  57. if(mp.count(in[dep])==0){
  58. solve(dep+1);
  59. return;
  60. }
  61. k = mp[in[dep]];
  62. for(i=(0);i<(sz[k]);i++){
  63. tmp[dep] = lis[k][i];
  64. solve(dep+1);
  65. }
  66. }
  67. class Solution{
  68. public:
  69. vector<string> generateSentences(vector<vector<string>>& S, string text){
  70. int i;
  71. mp.clear();
  72. tot = 0;
  73. for(i=(0);i<(10);i++){
  74. sz[i] = 0;
  75. }
  76. for(i=(0);i<(S.size());i++){
  77. int j;
  78. if(mp.count(S[i][0])){
  79. continue;
  80. }
  81. lis[tot][sz[tot]++] = S[i][0];
  82. mp[S[i][0]] = tot;
  83. lis[tot][sz[tot]++] = S[i][1];
  84. mp[S[i][1]] = tot;
  85. for(j=(i+1);j<(S.size());j++){
  86. if(mp.count(S[j][0]) && mp.count(S[j][1])){
  87. continue;
  88. }
  89. if(mp.count(S[j][0])){
  90. lis[tot][sz[tot]++] = S[j][1];
  91. mp[S[j][1]] = tot;
  92. continue;
  93. }
  94. if(mp.count(S[j][1])){
  95. lis[tot][sz[tot]++] = S[j][0];
  96. mp[S[j][0]] = tot;
  97. continue;
  98. }
  99. }
  100. tot++;
  101. }
  102. res.clear();
  103. tmp = in =Explode_L(text, " ");
  104. solve(0);
  105. sort(res.begin(), res.end());
  106. return res;
  107. }
  108. }
  109. ;
  110. // cLay varsion 20191123-1
  111.  
  112. // --- original code ---
  113. // #define main dummy_main
  114. // {}
  115. // #undef main
  116. //
  117. // map<string, int> mp;
  118. // string lis[10][20];
  119. // int tot, sz[10];
  120. // vector<string> res, in, tmp;
  121. //
  122. // void solve(int dep){
  123. // int k;
  124. // if(dep==in.size()) res.push_back( Implode(tmp, " ") ), return;
  125. // if(mp.count(in[dep])==0) solve(dep+1), return;
  126. // k = mp[in[dep]];
  127. // rep(i,sz[k]) tmp[dep] = lis[k][i], solve(dep+1);
  128. // }
  129. //
  130. // class Solution {
  131. // public:
  132. // vector<string> generateSentences(vector<vector<string>>& S, string text) {
  133. // mp.clear();
  134. // tot = 0;
  135. // rep(i,10) sz[i] = 0;
  136. //
  137. // rep(i,S.size()){
  138. // if(mp.count(S[i][0])) continue;
  139. // lis[tot][sz[tot]++] = S[i][0]; mp[S[i][0]] = tot;
  140. // lis[tot][sz[tot]++] = S[i][1]; mp[S[i][1]] = tot;
  141. // rep(j,i+1,S.size()){
  142. // if(mp.count(S[j][0]) && mp.count(S[j][1])) continue;
  143. // if(mp.count(S[j][0])) lis[tot][sz[tot]++] = S[j][1], mp[S[j][1]] = tot, continue;
  144. // if(mp.count(S[j][1])) lis[tot][sz[tot]++] = S[j][0], mp[S[j][0]] = tot, continue;
  145. // }
  146. // tot++;
  147. // }
  148. //
  149. // res.clear();
  150. // tmp = in = Explode(text, " ");
  151. // solve(0);
  152. // sort(res.begin(), res.end());
  153. // return res;
  154. // }
  155. // };
  156.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty