Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6.  
  7. void insertionSort(vector<int>& arr) {
  8. int key, j;
  9.  
  10. for (int i = 1; i < arr.size(); i++) {
  11. key = arr[i];
  12.  
  13. for (j = i - 1; j >= 0; j--) {
  14. if (arr[j] > key) {
  15. arr[j + 1] = arr[j];
  16. } else {
  17. break;
  18. }
  19. }
  20. arr[j + 1] = key;
  21. }
  22. }
  23.  
  24. // Complete the birthdayCakeCandles function below.
  25. int birthdayCakeCandles(vector<int> arr) {
  26. insertionSort(arr);
  27.  
  28. int heighest = arr[arr.size() - 1];
  29. int count = 1;
  30.  
  31. for(int i = 0; i < arr.size() - 1; i++) {
  32. if (heighest == arr[i]) {
  33. count++;
  34. }
  35. }
  36.  
  37. return count;
  38. }
  39.  
  40. int main()
  41. {
  42. ofstream fout(getenv("OUTPUT_PATH"));
  43.  
  44. int ar_count;
  45. cin >> ar_count;
  46. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  47.  
  48. string ar_temp_temp;
  49. getline(cin, ar_temp_temp);
  50.  
  51. vector<string> ar_temp = split_string(ar_temp_temp);
  52.  
  53. vector<int> ar(ar_count);
  54.  
  55. for (int i = 0; i < ar_count; i++) {
  56. int ar_item = stoi(ar_temp[i]);
  57.  
  58. ar[i] = ar_item;
  59. }
  60.  
  61. int result = birthdayCakeCandles(ar);
  62.  
  63. fout << result << "\n";
  64.  
  65. fout.close();
  66.  
  67. return 0;
  68. }
  69.  
  70. vector<string> split_string(string input_string) {
  71. string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  72. return x == y and x == ' ';
  73. });
  74.  
  75. input_string.erase(new_end, input_string.end());
  76.  
  77. while (input_string[input_string.length() - 1] == ' ') {
  78. input_string.pop_back();
  79. }
  80.  
  81. vector<string> splits;
  82. char delimiter = ' ';
  83.  
  84. size_t i = 0;
  85. size_t pos = input_string.find(delimiter);
  86.  
  87. while (pos != string::npos) {
  88. splits.push_back(input_string.substr(i, pos - i));
  89.  
  90. i = pos + 1;
  91. pos = input_string.find(delimiter, i);
  92. }
  93.  
  94. splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  95.  
  96. return splits;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement