Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef pair<char, int> letterWithWeight;
- int main() {
- //Ввод данных
- map<char, int> lettersWeight;
- map<char, int> lettersAmount;
- string input;
- string answer = "";
- cin >> input;
- char key = 'a';
- while (key - 1 != 'z') {
- int temp;
- cin >> temp;
- lettersAmount.insert(make_pair(key, 0));
- lettersWeight.insert(make_pair(key, temp));
- key += 1;
- }
- //Тело программы
- for (auto i: input) {
- lettersAmount[i] = lettersAmount[i] + 1;
- }
- for (auto i: input) {
- if (lettersAmount[i] % 2 != 0) {
- answer.insert(answer.end(), i);
- lettersAmount[i] = lettersAmount[i] - 1;
- }
- }
- // string temp = "";
- // int positionEnd = answer.size();
- // int prevPosition = positionEnd;
- // for (auto i : input){
- // if (lettersAmount[i] > 0){
- // if (!temp.empty()){
- // temp.insert(temp.begin(), i);
- // positionEnd = positionEnd + 2;
- // prevPosition = positionEnd;
- // lettersAmount[i] = lettersAmount[i] - 2;
- // } else {
- // int index = 0;
- // for (int j = 0; j < temp.size(); j++){
- // if ((lettersWeight[temp[j]] * positionEnd) > (lettersWeight[i]*positionEnd)){
- // index +=1;
- // }
- // }
- // temp.insert(temp.begin() + index, i);
- // }
- // }
- // }
- string partOfAnswer = "";
- int positionEnd = answer.size() + 1;
- while (positionEnd != input.size()) {
- int min = INT64_MAX;
- char temp;
- for (auto p: lettersAmount) {\
- if (p.second > 0) {
- if (p.second * positionEnd < min) {
- temp = p.first;
- min = p.second * positionEnd;
- }
- }
- }
- lettersAmount[temp] = lettersAmount[temp] - 2;
- partOfAnswer.insert(partOfAnswer.begin(), temp);
- positionEnd +=1;
- }
- cout << partOfAnswer << endl;
- //Вывод данных
- cout << answer;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement