判断题,有点绕,注意在答案不唯一时的判断条件要依据B数组判断
#include <iostream> #include <algorithm> #include <map> using namespace std; int b[110000],f[110000]; map <int,int> Map,A; int main() { int n,i,m; cin >> n >> m; for(i=1;i<=n;++i) { cin >> f[i]; if(!Map[f[i]])Map[f[i]]=i; else { A[f[i]]=true; } } for(i=1;i<=m;++i) { cin >> b[i]; if(!Map[b[i]]) { cout << "Impossible" << endl; return 0; } } for(i=1;i<=m;++i) { if(A[b[i]]) { cout << "Ambiguity" << endl; return 0; } } cout << "Possible" << endl; for(i=1;i<=m;++i) { cout << Map[b[i]] << ‘ ‘; } cout << endl; return 0; }
时间: 2024-10-18 16:40:09