fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool comparator(const pair<string, string> &a, const pair<string, string> &b)
  4. {
  5. if (a.second != b.second)
  6. return a.second < b.second;
  7. return a.first < b.first;
  8. }
  9.  
  10. int main()
  11. {
  12.  
  13. // prime order has alphanumeric code + lowercase metadata
  14. // non-prime orders has alphanumeric code + space delimted list of positve integers
  15.  
  16. // considering input is given as an array of strings
  17. vector<string> t = {"zld 93 12",
  18. "fp kindle book",
  19. "10a echo show",
  20. "17g 12 25 6",
  21. "ab1 kindle book",
  22. "125 echo dot second generation"};
  23. vector<pair<string, string>> prime, non_prime;
  24.  
  25. for (int i = 0; i < t.size(); i++)
  26. {
  27. string s = t[i];
  28.  
  29. string w = "";
  30. vector<string> temp;
  31.  
  32. int cnt = 0;
  33. for (int j = 0; j < s.size(); j++)
  34. {
  35. if (s[j] == ' ')
  36. {
  37. if (cnt == 0)
  38. {
  39. temp.push_back(w);
  40. cnt++;
  41. w = "";
  42. }
  43. else
  44. {
  45. w += " ";
  46. }
  47. }
  48. else
  49. {
  50. w += s[j];
  51. }
  52. }
  53. temp.push_back(w);
  54.  
  55. if (temp.size() > 1 and temp[1][0] >= 48 and temp[1][0] <= 57)
  56. non_prime.push_back({temp[0], temp[1]});
  57. else if (temp.size() > 1)
  58. prime.push_back({temp[0], temp[1]});
  59. }
  60.  
  61. sort(begin(prime), end(prime), comparator);
  62. for (int i = 0; i < prime.size(); i++)
  63. {
  64. cout << prime[i].first << " " << prime[i].second << endl;
  65. }
  66. for (int i = 0; i < non_prime.size(); i++)
  67. {
  68. cout << non_prime[i].first << " " << non_prime[i].second << endl;
  69. }
  70. return 0;
  71. }
Success #stdin #stdout 0s 5260KB
stdin
Standard input is empty
stdout
125 echo dot second generation
10a echo show
ab1 kindle book
fp kindle book
zld 93 12
17g 12 25 6