fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. string lowercase(const string str)
  7. {
  8. string result(str);
  9. for(int i = 0; i < str.length(); ++i)
  10. result[i] = tolower(result[i]);
  11. return result;
  12. }
  13.  
  14. int main()
  15. {
  16. int n = 0;
  17. string buffer;
  18.  
  19. cin >> n;
  20. getline(cin, buffer);
  21.  
  22. for(int i = 0; i < n; ++i)
  23. {
  24. string str[4];
  25. if(i)
  26. cout << endl;
  27. getline(cin, buffer);
  28. while(buffer[0] == ' ')
  29. buffer.erase(0, 1);
  30. while(buffer[buffer.length() - 1] == ' ')
  31. buffer.erase(buffer.length() - 1, 1);
  32. while(buffer.find(" ") != string::npos)
  33. buffer.erase(buffer.find(" "), 1);
  34.  
  35. int temp = 0;
  36. bool lastspace = false;
  37. for(int j = 0; j < 4 && !lastspace; ++j)
  38. {
  39. int idx = buffer.find_first_of(' ', temp);
  40. lastspace = idx == string::npos;
  41. str[j] = lowercase(buffer.substr(temp, idx - temp));
  42. temp = idx + 1;
  43. }
  44.  
  45. if(str[0].length() > 1)
  46. {
  47. if(str[0].substr(str[0].length() - 2) == "'s")
  48. {
  49. cout << "Set";
  50. continue;
  51. }
  52. }
  53. if(!lastspace || str[0] == "damaged" || str[1] == "")
  54. {
  55. cout << "Normal";
  56. continue;
  57. }
  58. if((str[1] == "of" && str[2] != "" && str[3] == "") || (str[2] == "of" && str[3] != "" && lastspace))
  59. {
  60. cout << "Magic";
  61. continue;
  62. }
  63. if(str[0] == "of" && str[1] != "" && str[2] == "")
  64. {
  65. cout << "Rare";
  66. continue;
  67. }
  68. if(str[1] != "" && str[2] == "")
  69. {
  70. cout << "Not sure, take anyways";
  71. continue;
  72. }
  73. cout << "Normal";
  74. }
  75.  
  76. return 0;
  77. }
Success #stdin #stdout 0s 2992KB
stdin
11
 Somebody's Something of Whatever
stone  of  jordan 
Wirt's Leg
FLAMING  TURNIP
Damaged Goods
Sword
Fish shaped volatile organic compounds
Jodarn's
Jordan''s sword
's sword
's
stdout
Set
Magic
Set
Not sure, take anyways
Normal
Normal
Normal
Set
Set
Set
Set