Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<unordered_map>
- #include<forward_list>
- #include<utility>
- const std::forward_list<unsigned>& input(unsigned N)
- {
- static std::forward_list<unsigned> ls;
- unsigned temp=0;
- while(N--){
- std::cin>>temp;
- ls.push_front(std::move(temp));
- }
- return ls;
- }
- std::unordered_map<unsigned,unsigned>& squared(unsigned N)
- {
- static std::unordered_map<unsigned,unsigned> ht;
- unsigned temp=0;
- while(N--){
- std::cin>>temp;
- bool found=ht.find(temp)!=ht.end();
- if(!found)
- ht.insert(std::pair<unsigned,unsigned>(temp,1));
- else
- ht[temp]++;
- }
- return ht;
- }
- bool same(const std::forward_list<unsigned>& ls,std::unordered_map<unsigned,unsigned>& ht)
- {
- for(const auto& i: ls){
- unsigned sq=i*i;
- bool found=ht.find(sq)!=ht.end();
- if(!found)
- return 0;
- else{
- ht[sq]--;
- if(!ht[sq])
- ht.erase(sq);
- }
- }
- return 1;
- }
- int main()
- {
- std::cout<<"Enter the limit: ";
- unsigned N=0;
- std::cin>>N;
- std::cout<<same(input(N),squared(N))<<std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement