Предмет: Информатика, автор: A1l9i8n4a

дуже срочно даю 100 б
с++

На вхід функція приймає восьмизначне число. Необхідно з даного числа видалити усі цифри, що повторюються крім першої їх появи. Функція повинна повертати «відсортоване» число, яке необхідно вивести на екран. Наприклад: 51231242 ->51234.


experced: дай мне 5 минут

Ответы

Автор ответа: experced
0

#include <iostream>

#include <unordered_set>

#include <algorithm>

using namespace std;

int removeDuplicateDigits(int number) {

   string numStr = to_string(number);

   unordered_set<char> seenDigits;

   string result = "";

   for (char digit : numStr) {

       if (seenDigits.find(digit) == seenDigits.end()) {

           seenDigits.insert(digit);

           result += digit;

       }

   }

   sort(result.begin(), result.end());

   return stoi(result);

}

int main() {

   int number;

   cout << "Введите восьмизначное число: ";

   cin >> number;

   int sortedNumber = removeDuplicateDigits(number);

   cout << "Отсортированное число: " << sortedNumber << endl;

   return 0;

}


experced: если есть вопросы по работе программы, спрашивай
Похожие вопросы
Предмет: Английский язык, автор: tupikinakr
1. What _______ beautiful girl! a) a b) the c) zero article Ответ: а 2._______ lily is my favourite flower. a) a b) the c) zero article Ответ: b 3. I’ll do it _________. a) Yourself b) himself c) myself Ответ: b 4. He is always busy. I don’t want to phone _______ . a) him b) them c) his Ответ: с 5. I was disappointed that my results were ______ . a) badly b) good c) bad 6. You look _______. Have you lost weight? a) thin b) more thin c) thinner 7. It is _______ experience of my life. a) bad b) the worst c) worse 8. Our university has a rule - all classes have to begin ____8 o'clock. a) in b) over c) at 9. On Fridays we have four classes but ____ Saturdays we have days off. a) in b) on c) about 10. ________ a long break we prefer having a wholesome meal. a) in b) during c) over 11. Jack and Laura _______ the best students in the group. a) was b) is с) are 12. It _____ really cold yesterday. a) is b) was с) has been 13. _________ any butter in the fridge? a) is there b) are there с) there are 14. Liz _________at a primary school. a) teach b) teachs c) teaches 15. The girl in the painting ___________ a blue dress. a) wears b) wearing c) is wearing 16. Unfortunately Sonia ___________ a job. a) hasn’t b) doesn’t have c) don’t have 17. Where ______ you _________yesterday? a) do / go b) did / went c) did / go 18. My father _________ English very well at school. a) knows b) knew c) knowed 19. We _______while our mother _______. a) are making a salad / was baking a pie. b) were making a salad / was baking a pie. c) made a salad / had baked a pie. 20. He will miss the train if he _______ a taxi. a) won’t take b) doesn’t take c) didn’t take 21. – There is no bread. - Don’t worry. I _________ some. a) buy b) would buy c) will buy 22. By the end of the month we ________ the diplomas. a) will get b) will have got c) get 23. _______you (to see) Mary today? a) Has / seen b) Did / see c) Have / seen 24. They________ by 6 o’clock yesterday. a) were doing all the housework. b) had done all the housework. c) did all the housework. 25. After the director _________the presentation, they started the discussion. a) was making b) has made c) had made 26. The hotel __________ next year. a) will be opened b) is opened c) was opened 27. This house _______ by my grandfather fifty years ago. a) is built b) was built c) will be built 28. I ______ often ______ to parties. a) am not invited b) is not invited c) will not be invited 29. Don’t come in! The students _______. a) are examined b) were examined c)are being examined 30. The telegram _______ by 3 o’ clock tomorrow. a) will be sent b) has been sent c) will have been sent