Advertisement
stupid_pro

Untitled

Nov 30th, 2021
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4. string to_binary_string(unsigned int n)
  5. {
  6. string buff;
  7. buff.reserve(numeric_limits<unsigned long long>::digits);
  8. do
  9. {
  10. buff += char('0' + n % 2);
  11. n /= 2;
  12. } while (n > 0);
  13. return string(buff.crbegin(), buff.crend());
  14. }
  15. int main()
  16. {
  17. int n;
  18. long long age, counter=0, number_of_candles=999, total, arr[100];
  19. string ageStr;
  20. cin >>n;
  21. for (int i=0; i<n; i++) cin >>arr[i];
  22. for (int i=0; i<n; i++)
  23. {
  24. ageStr= to_binary_string(arr[i]);
  25. if (i==0)
  26. {
  27. number_of_candles=ageStr.size();
  28. total=number_of_candles;
  29. }
  30. else
  31. {
  32. for (int k=number_of_candles; k<ageStr.size(); k++)
  33. {
  34. number_of_candles++;
  35. total++;
  36. }
  37.  
  38. }
  39. for (int j=0; j<ageStr.size(); j++) if (ageStr[j]=='1') counter++; //считаем количество единиц
  40. number_of_candles-=counter; //считаем, сколько осталось после первого торта
  41. counter=0;
  42. }
  43. cout <<total;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement