fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct p {
  5. char ch4;
  6. //char ch5;
  7. string ch6;
  8. //char ch6[30];
  9. }
  10. stud[20170];
  11.  
  12. struct q
  13. {
  14. string ch8;
  15. char ch7;
  16. }
  17. plusi[20170];
  18.  
  19. struct pp
  20. {
  21.  
  22. string ch11;
  23. }
  24. pl[200170];
  25.  
  26. int ww;
  27.  
  28. int paras[100000];
  29.  
  30. string paras2;
  31. int main()
  32. {
  33. int a,b,c,d,e,f,z,y,x,w,k,maxi,r,m,n;bool flag=0;bool flag2=0;int vali=0;
  34. char ch10;
  35. fflush(stdin);
  36. //cout<<"hi\n";
  37. cin>>a;
  38. e=0;f=0;
  39. memset(paras,0,sizeof(paras));
  40. for(b=0;b<a;b++)
  41. {
  42. cin>>ch10;
  43. if(ch10=='-'){
  44. cin>>stud[e].ch6;
  45.  
  46. e++;}
  47. else{
  48. plusi[f].ch7 = '+';
  49. cin>>plusi[f].ch8;
  50. paras[plusi[f].ch8[0]]++;f++;}
  51.  
  52. }
  53. if(e==0 || f==0)
  54. {
  55. if(e==0)
  56. {
  57. cout<<"0\n";
  58. }
  59. else
  60. {
  61. m = e;
  62.  
  63. vector < string > pl;string par;
  64. for(r=0;r<m;r++)
  65. { //cout<<stud[b].ch6[r];
  66. par = stud[r].ch6[0];
  67. pl.push_back(par);
  68. }
  69. sort( pl.begin(), pl.end() );
  70. pl.erase( unique( pl.begin(), pl.end() ), pl.end() );
  71. vector < string > :: iterator it;
  72. m = pl.size();
  73. cout<<m<<"\n";
  74. for(it=pl.begin();it!=pl.end();it++)
  75. {
  76. cout<<*it<<"\n";
  77. }
  78.  
  79. }
  80.  
  81.  
  82. }
  83.  
  84. else{
  85.  
  86. m=0;flag2=0;
  87. for(b=0;b<e;b++)//minus
  88. {
  89. z = stud[b].ch6.size();maxi=0;flag=0;flag2=0;
  90. if(paras[stud[b].ch6[0]]==0)
  91. {
  92. maxi =0;pl[m].ch11 = stud[b].ch6[0];m++;
  93. }
  94. else
  95. {
  96. for(c=0;c<f;c++)//plus
  97. {
  98. // vali = strcmp(stud[b].ch6,plusi[c].ch8);
  99. y = plusi[c].ch8.size();k=0;flag=0;flag2=0;//length of plus
  100. if(plusi[c].ch8==stud[b].ch6)
  101. {
  102. flag=0;flag2=1;break;
  103. }
  104. else{
  105.  
  106. paras2 = string (plusi[c].ch8.begin(),
  107. std::mismatch(plusi[c].ch8.begin(), plusi[c].ch8.end(), stud[b].ch6.begin()).first);
  108. // cout<<paras2;
  109. int yy=0;
  110. yy = paras2.size();
  111. //cout<<c;
  112. if(paras2==" " || paras2=="\0")
  113. {
  114. k = 0;flag=1;
  115. }
  116. else if(z==yy)
  117. {
  118. flag=0;flag2=1;break;
  119. }
  120. else if(z>yy)
  121. {
  122. k = yy;flag=1;
  123. }
  124.  
  125. }
  126. //cout<<paras2<<"\n";
  127. if(flag==0)
  128. {
  129. maxi=0;flag2 =1;break;
  130. }
  131. else if(k>maxi)
  132. {
  133. maxi =k;
  134. }
  135. }
  136. if(flag2==1)
  137. break;
  138. else if(maxi>0 || flag==1){
  139. stud[b].ch6.erase(stud[b].ch6.begin()+maxi+1,stud[b].ch6.end());
  140. //cout<<stud[b].ch6[r];
  141. pl[m].ch11 = stud[b].ch6;m++;}
  142.  
  143. }}
  144. //cout<<pl[m-1].ch11<<"\n";
  145.  
  146. // std::sort(pl, pl+m, acompare);
  147.  
  148. //cout<<m<<"\n";
  149.  
  150. if(m==0 || flag2==1)
  151. m=-1;
  152. else{}
  153. vector < string > po;string par;
  154. if(m>0){
  155. // vector < string > po;string par;
  156. for(r=0;r<m;r++)
  157. { //cout<<pl[r].ch11;
  158.  
  159. par = pl[r].ch11;
  160. po.push_back(par);
  161. }
  162. sort( po.begin(), po.end() );
  163. po.erase( unique( po.begin(), po.end() ), po.end() );
  164. vector < string > :: iterator it;
  165. m = po.size();
  166. }
  167. else{}
  168. vector < string > :: iterator it;
  169. cout<<m<<"\n";
  170. for(it=po.begin();it!=po.end();it++)
  171. {
  172. cout<<*it<<"\n";
  173. }
  174. }
  175.  
  176. }
Success #stdin #stdout 0s 23456KB
stdin
Standard input is empty
stdout
0