fork download
  1. /* (C) WhiZTiM 2013 */
  2. #include <iostream>
  3. #include <string>
  4. #include <cstring>
  5. #include <vector>
  6.  
  7. using namespace std;
  8. typedef string::size_type szT;
  9. typedef vector<string> VEC_string;
  10.  
  11. void strip_common_characters(string& A, string& B)
  12. {
  13. //choose the shortest string to save iteration time
  14. string& S1 = A.size() <= B.size() ? A : B; //by reference!
  15. string& S2 = A.size() > B.size() ? A : B; //by reference!
  16. szT i = 0;
  17. while(i < S1.size())
  18. {
  19. bool found = false;
  20. szT lc = S2.find(S1[i]);
  21. if(lc != string::npos) found = true;
  22. else
  23. {
  24. lc = S2.find(tolower(S1[i]));
  25. if(lc != string::npos) found = true;
  26. }
  27. if(found)
  28. {
  29. S1.erase(i, 1);
  30. S2.erase(lc,1);
  31. continue;
  32. }
  33. ++i;
  34. }
  35. }
  36.  
  37. void instantiateMap(VEC_string& mp)
  38. {
  39. mp.push_back("Friends");
  40. mp.push_back("Lovers");
  41. mp.push_back("Admirers");
  42. mp.push_back("Married");
  43. mp.push_back("Enemies");
  44. mp.push_back("Sisters");
  45. }
  46.  
  47. void run()
  48. {
  49. string s1, s2, s3, s4;
  50. getline(cin, s1);
  51. getline(cin, s2);
  52. s3 = s1; s4 = s2;
  53.  
  54. VEC_string mp;
  55. instantiateMap(mp);
  56.  
  57. strip_common_characters(s1, s2);
  58. unsigned k = s1.size() + s2.size();
  59. k = (k - 1) < 0 ? 0 : ((k - 1) % mp.size());
  60.  
  61. cout << s3 << " and " << s4 << " are " << mp[k] << endl;
  62. }
  63.  
  64. int main(int argc, char* argv[])
  65. {
  66. run();
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0s 2992KB
stdin
Elvis
Lois
stdout
Elvis and Lois are Admirers