fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. string ltrim(const string &);
  6. string rtrim(const string &);
  7. vector<string> split(const string &);
  8.  
  9. /*
  10.  * Complete the 'birthdayCakeCandles' function below.
  11.  *
  12.  * The function is expected to return an INTEGER.
  13.  * The function accepts INTEGER_ARRAY candles as parameter.
  14.  */
  15.  
  16. int birthdayCakeCandles(vector<int> candles) {
  17. sort(candles.begin(),candles.end());
  18. int cnt=1;
  19. int n=candles.size()-1;
  20. int k=n-1;
  21. while(candles[n]==candles[k--]){
  22. cnt++;
  23. }
  24. return cnt;
  25. }
  26.  
  27. int main()
  28. {
  29. ofstream fout(getenv("OUTPUT_PATH"));
  30.  
  31. string candles_count_temp;
  32. getline(cin, candles_count_temp);
  33.  
  34. int candles_count = stoi(ltrim(rtrim(candles_count_temp)));
  35.  
  36. string candles_temp_temp;
  37. getline(cin, candles_temp_temp);
  38.  
  39. vector<string> candles_temp = split(rtrim(candles_temp_temp));
  40.  
  41. vector<int> candles(candles_count);
  42.  
  43. for (int i = 0; i < candles_count; i++) {
  44. int candles_item = stoi(candles_temp[i]);
  45.  
  46. candles[i] = candles_item;
  47. }
  48.  
  49. int result = birthdayCakeCandles(candles);
  50.  
  51. fout << result << "\n";
  52.  
  53. fout.close();
  54.  
  55. return 0;
  56. }
  57.  
  58. string ltrim(const string &str) {
  59. string s(str);
  60.  
  61. s.erase(
  62. s.begin(),
  63. find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
  64. );
  65.  
  66. return s;
  67. }
  68.  
  69. string rtrim(const string &str) {
  70. string s(str);
  71.  
  72. s.erase(
  73. find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
  74. s.end()
  75. );
  76.  
  77. return s;
  78. }
  79.  
  80. vector<string> split(const string &str) {
  81. vector<string> tokens;
  82.  
  83. string::size_type start = 0;
  84. string::size_type end = 0;
  85.  
  86. while ((end = str.find(" ", start)) != string::npos) {
  87. tokens.push_back(str.substr(start, end - start));
  88.  
  89. start = end + 1;
  90. }
  91.  
  92. tokens.push_back(str.substr(start));
  93.  
  94. return tokens;
  95. }
  96.  
Success #stdin #stdout 0.01s 5468KB
stdin
4
3 2 1 3
stdout
Standard output is empty