zoukankan      html  css  js  c++  java
  • 1116 贪婪的送礼者

    花费了一下午做出了这道题,真有些伤人伤不起;

    题目描述在下面地址

    http://www.nputic.com/JudgeOnline/problem.php?id=1116

    题目不难理解,但我感觉真心不好做,处理关系时不会,

    通过这题对 map的用法用增加了一个层次;

    map 中输入和输出顺序不相同,所以利用vector来标记;

    #include<iostream>
    #include<vector>
    # include <string>
    # include <map>

    using namespace std;

    vector<string> vi;
    map<string, int> person;
    map<string, int> ::iterator iter;

    int main()
    {
    int NP;

    cin >> NP;
    string strp;

    for(int i = 1; i <= NP; i++) {
    cin >> strp;

    vi.push_back(strp);

    person[strp] = 0;

    }

    for(int i = 1; i <= NP; i++)
    {
    int money, peo,ave;
    string Giver;
    cin >> Giver;
    cin >> money>>peo;

    if(peo)
    {
    money = money / peo;

    }

    for(int j = 1; j <= peo; j++)//题目中把不能给出的钱留给自己,这样合并写利用了强制转换,十分方便;
    {
    cin >> strp;
    person[Giver] -= money;
    person[strp] += money;
    }
    }

    for(int i=0;i<NP;i++)
    {
    for(iter = person.begin(); iter != person.end(); iter++)
    {
    if(iter->first == vi[i])
    cout << iter->first << " " << iter->second << endl;

    }

    }
    }

  • 相关阅读:
    iOS13 present VC方法
    青囊奥语
    三元九运的排盘
    三元九运 笔记
    青囊经
    金钱卦起卦
    易经中九二六三是什么意思
    用神
    六爻预测中的世爻,应爻分别代表什么
    div2-1519-D-Maximum Sum of Products-dp
  • 原文地址:https://www.cnblogs.com/lfyy/p/2797612.html
Copyright © 2011-2022 走看看