其他分享
首页 > 其他分享> > PAT 1048 Find Coins (25 分) map or Hash散列

PAT 1048 Find Coins (25 分) map or Hash散列

作者:互联网

#include<iostream>
#include<map>
using namespace std;

int main(){
    int n,m,temp;
    cin>>n>>m;
    map<int,int>mapp;
    for(int i=0;i<n;i++){
        scanf("%d",&temp);
        mapp[temp]++;             //key为硬币面额,value为数量
    }
    int flag=0;
    for(auto it=mapp.begin();it!=mapp.end();it++){          //map中键自动排序(红黑树)
        int t1=it->first,t2=m-t1;
        it->second--;    			//t1数值的硬币数量--
        if(mapp[t2]!=0) {
            cout<<t1<<" "<<t2;
            flag=1;
            break;
        }
    }
    if(flag==0)cout<<"No Solution";
    system("pasue");
    return 0;
}

标签:25,PAT,temp,map,int,1048,t1,mapp,include
来源: https://blog.csdn.net/m0_48711099/article/details/122857620