fork(2) download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<string>
  4. #include<cstring>
  5. using namespace std;
  6. string s ;
  7. //cin >> s;
  8. int gettingIndex(string a , string s) {
  9. return s.find(a);
  10.  
  11. }
  12. bool compare(string a, string b) {
  13.  
  14. int x = gettingIndex(a, s);
  15.  
  16. int y = gettingIndex(b , s);
  17. if (x == y) {
  18. return a.length() < b.length();
  19. }
  20.  
  21. return x < y;
  22. }
  23.  
  24.  
  25. string stringRemover(string &s, string sample) {
  26. int index = s.find(sample);
  27.  
  28. while (index >= 0) {
  29. int len = sample.length();
  30. s.erase(index, len);
  31.  
  32. index = s.find(sample);
  33. }
  34. return s;
  35. }
  36. int main() {
  37. #ifndef ONLINE_JUDGE
  38. freopen("input.txt" , "r", stdin);
  39. freopen("output.txt", "w", stdout);
  40. #endif
  41.  
  42. // string s ;
  43. cin >> s;
  44. int n;
  45. cin >> n;
  46. string s1[n];
  47. for (int i = 0; i < n; i++) {
  48. cin >> s1[i];
  49. }
  50.  
  51. sort(s1, s1 + n, compare);
  52.  
  53. for (int i = 0; i < n; i++) {
  54.  
  55. stringRemover(s, s1[i]);
  56. }
  57. cout << s ;
  58.  
  59. }
Success #stdin #stdout 0s 4368KB
stdin
KUKUKAKIKUKAKEKKUKAKAKKUKAKUKAKU
2
KEK
UK
stdout
KAKIKAKAKAKKAKAKU